Reference vars in php would not be unset if it reference by another
var,so you must keep original var had'nt being reference.
2009/9/3 Martin Zvarík <mzva...@gmail.com>:
> AHA !!!
>
> OMG... how come I did not see that!?
>
> Instead this:
> $array =& $array[$final];
> unset($array);
>
> This:
> unset($array[$final]);
>
>
> 3 AM in the morning... that must be the reason! .)
>
> Thanks.
>
>
>
>>
>> This is possible. You're just not giving enough consideration to your exit
>> strategy :)
>>
>> <?php
>>
>> function unset_deep( &$array, $keys )
>> {
>>    $final = array_pop( $keys );
>>
>>    foreach( $keys as $key )
>>    {
>>        $array = &$array[$key];
>>    }
>>
>>    unset( $array[$final] );
>> }
>>
>> $value = array
>> (
>>    'a' => array
>>    (
>>        'b' => array
>>        (
>>            'c' => 'C',
>>            'd' => 'D',
>>            'e' => 'E'
>>        ),
>>    ),
>> );
>>
>> $keys = array('a', 'b', 'c');
>> unset_deep( $value, $keys );
>>
>> print_r( $value );
>>
>> ?>
>>
>> Cheers,
>> Rob.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to