note 94301 added to function.unset
| From: | fsockopen_AT_yahoo_DOT_it at osu1 dot php dot net | Date: | Wed, 28 Oct 2009 11:28:51 +0000 |
| Subject: | note 94301 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162170@lists.php.net to get a copy of this message | ||
if have a configuration array like this:
$options = array(
'foo' => array(
'bar' => array(
'baz' = 'something'
)
)
'fruit' => 'apple'
};
I was searching a way to remove a part (the 'baz' element) of the array
starting from a syntax like:
remove foo.bar.baz
or
foo/bar/baz
<?php
$optionToRemove = 'foo.bar.baz';
$separator = '.'; // or "/"
$parts = explode($separator, $optionToRemove);
$GLOBALS['tmpvar'] = $options;
$evalString = 'unset($GLOBALS['tmpvar']["' .
implode('"]["', $parts) . '"]);';
eval($evalString);
$options = $GLOBALS['tmpvar'];
unset($GLOBALS['tmpvar']);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 151.13.101.114
----
Manual Page -- http://www.php.net/manual/en/function.unset.php
Edit -- https://master.php.net/note/edit/94301
Del: integrated -- https://master.php.net/note/delete/94301/integrated
Del: useless -- https://master.php.net/note/delete/94301/useless
Del: bad code -- https://master.php.net/note/delete/94301/bad+code
Del: spam -- https://master.php.net/note/delete/94301/spam
Del: non-english -- https://master.php.net/note/delete/94301/non-english
Del: in docs -- https://master.php.net/note/delete/94301/in+docs
Del: other reasons-- https://master.php.net/note/delete/94301
Reject -- https://master.php.net/note/reject/94301
Search -- https://master.php.net/manage/user-notes.php