public static function recursive_unset(&$obj, $path)
    {
        $i = 1;
        foreach (($l = explode('|', $path)) as $key) {
            if (is_object($obj)) {
                if (isset($obj->$key)) {
                    if (count($l) === $i) {
                        unset($obj->$key);
                        return true;
                    }
                    $obj = &$obj->$key;
                } else {
                    return false;
                }
            } else {
                if (isset($obj[$key])) {
                    if (count($l) === $i) {
                        unset($obj[$key]);
                        return true;
                    }
                    $obj = &$obj[$key];
                } else {
                    return false;
                }
            }   
            $i++;
        }
        return null;
    }
public static function recursive_unset(&$obj, $path)
    {
        $i = 1;
        foreach (($l = explode('|', $path)) as $key) {
            if (is_object($obj)) {
                if (isset($obj->$key)) {
                    if (count($l) === $i) {
                        unset($obj->$key);
                        return true;
                    }
                    $obj = &$obj->$key;
                } else {
                    return false;
                }
            } else {
                if (isset($obj[$key])) {
                    if (count($l) === $i) {
                        unset($obj[$key]);
                        return true;
                    }
                    $obj = &$obj[$key];
                } else {
                    return false;
                }
            }   
            $i++;
        }
        return null;
    }
public static function recursive_unset ( & $ obj , $ path ) { $ i = 1 ; foreach ( ( $ l = explode ( '|' , $ path ) ) as $ key ) { if ( is_object ( $ obj ) ) { if ( isset ( $ obj -> $ key ) ) { if ( count ( $ l ) === $ i ) { unset ( $ obj -> $ key ) ; return true ; } $ obj = & $ obj -> $ key ; } else { return false ; } } else { if ( isset ( $ obj [ $ key ] ) ) { if ( count ( $ l ) === $ i ) { unset ( $ obj [ $ key ] ) ; return true ; } $ obj = & $ obj [ $ key ] ; } else { return false ; } } $ i ++ ; } return null ; }
Handy function to unset a deep value of a class or an array.

@access public
@param  mixed  $obj  the class or array containing the value to be unset.
@param  string $path the key or key-path (foo|bar|some|thing)
@return mixed        true if unset, false if key does not exist, null if key is invalid.
Handy function to unset a deep value of a class or an array .