Re: Array references - how to unset() ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux