note 119796 added to function.unset
| From: | goran77 at fastmail dot fm | Date: | Sun, 28 Aug 2016 13:26:53 +0000 |
| Subject: | note 119796 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206409@lists.php.net to get a copy of this message | ||
$a = ['x', 'y'];
// we are looking for index of 'x',
// and we are getting 0 as result
$index = array_search('x', $a);
// this removes element with index 0 ('x'). So far so good.
unset ($a[$index]);
print_r ($a); // Array ( [1] => y )
// BUT, if we were looking for non-existent element,
// we'll get FALSE as result...
$a = ['x', 'y'];
$index = array_search('z', $a); //here $index is false, not zero
// ...but it will also remove 'x'
unset ($a[$index]);
----
Server IP: 72.52.91.14
Probable Submitter: 95.178.196.175
----
Manual Page -- http://php.net/manual/en/function.unset.php
Edit -- https://master.php.net/note/edit/119796
Del: integrated -- https://master.php.net/note/delete/119796/integrated
Del: useless -- https://master.php.net/note/delete/119796/useless
Del: bad code -- https://master.php.net/note/delete/119796/bad+code
Del: spam -- https://master.php.net/note/delete/119796/spam
Del: non-english -- https://master.php.net/note/delete/119796/non-english
Del: in docs -- https://master.php.net/note/delete/119796/in+docs
Del: other reasons-- https://master.php.net/note/delete/119796
Reject -- https://master.php.net/note/reject/119796
Search -- https://master.php.net/manage/user-notes.php