Posted By

thesmart on 04/02/10


Tagged

array recursive key associative unset


Versions (?)

Recursively unset an array key


 / Published in: PHP
 

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.

  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  

You need to login to post a comment.