Re: Array references - how to unset() ?
| From: | Martin Zvarík | Date: | Thu, 03 Sep 2009 01:04:46 +0000 |
| Subject: | Re: Array references - how to unset() ? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297619@lists.php.net to get a copy of this message | ||
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.