Recursively unset an array key


/ Published in: PHP
Save to your folder(s)

This function takes an array and a key that is unwanted. It will recurse through and unset the key in the argument array and all its sub-arrays.


Copy this code and paste it in your HTML
  1. function recursive_unset(&$array, $unwanted_key) {
  2. unset($array[$unwanted_key]);
  3. foreach ($array as &$value) {
  4. if (is_array($value)) {
  5. recursive_unset($value, $unwanted_key);
  6. }
  7. }
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.