Return to Snippet

Revision: 25615
at April 2, 2010 16:46 by thesmart


Initial Code
function recursive_unset(&$array, $unwanted_key) {
    unset($array[$unwanted_key]);
    foreach ($array as &$value) {
        if (is_array($value)) {
            recursive_unset($value, $unwanted_key);
        }
    }
}

Initial URL


Initial Description
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.

Initial Title
Recursively unset an array key

Initial Tags
array

Initial Language
PHP