note 123310 added to function.array-search
| From: | venkatesh dot ksnadar at gmail dot com | Date: | Tue, 06 Nov 2018 11:49:41 +0000 |
| Subject: | note 123310 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209633@lists.php.net to get a copy of this message | ||
you need to be careful if you are using array_search() with unset() for deleting a value in the
searched indexed
// wrong way
$checked = ["1", "2", "3"]; // array with numbers in double quotes
unset($checked[array_search('on', $checked)]); // this deletes value at 0 index
// array_search returns mixed data type, which means any type of data will be returned
// in the above case it returned false and false is type casted to 0
// so it deletes the value at index zero
the point to say is never use array_search() with unset() while deleting a value in an array using
index.
----
Server IP: 208.43.231.9
Probable Submitter: 1.186.249.182
----
Manual Page -- http://php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/123310
Del: integrated -- https://master.php.net/note/delete/123310/integrated
Del: useless -- https://master.php.net/note/delete/123310/useless
Del: bad code -- https://master.php.net/note/delete/123310/bad+code
Del: spam -- https://master.php.net/note/delete/123310/spam
Del: non-english -- https://master.php.net/note/delete/123310/non-english
Del: in docs -- https://master.php.net/note/delete/123310/in+docs
Del: other reasons-- https://master.php.net/note/delete/123310
Reject -- https://master.php.net/note/reject/123310
Search -- https://master.php.net/manage/user-notes.php