Re: Array references - how to unset() ?
| From: | Martin Zvarík | Date: | Wed, 02 Sep 2009 22:55:44 +0000 |
| Subject: | Re: Array references - how to unset() ? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297616@lists.php.net to get a copy of this message | ||
Robert Cummings napsal(a):
Martin Zvarík wrote:unset($ARR['a']['b']) Imagine I have this: $KEYS = array('a', 'b', 'c'); And I want to: unset($ARR['a']['b']['c']) It's probably impossible, unless I do something dirty like this: list($rootA, $rootB, $rootC) = $KEYS; if (isset($rootC)) unset($x[$rootA][$rootB][$rootC]); elseif (isset($rootB)) unset($x[$rootA][$rootB]); elseif (isset($rootA)) unset($x[$rootA]);$ARR = array( 'a' => array('b' => 'blah') ); function set($key) {unset( $ARR[$k] ) Cheers, Rob. Thanks for reply, but I want to:global $ARR;foreach ($key as $i => $k) { if ($i == 0) { $sourcevar =& $ARR[$k]; } else { $sourcevar =& $sourcevar[$k]; } }// unset($sourcevar); // will cancel the reference - we want to unset the ['b'], but how?$sourcevar = null; // will set it NULL, but won't unset... foreach ($ARR ... // I could run a cleanup, that would go through all of the array and unset what is NULL, but I would need to use REFERENCES again!! array_walk_recursive() is also worthless... any ideas? } set( array('a', 'b') );