note 71293 added to function.array-search
| From: | ElwinvanHuissteden at osu1 dot php dot net | Date: | Tue, 21 Nov 2006 13:19:10 +0000 |
| Subject: | note 71293 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119939@lists.php.net to get a copy of this message | ||
Appearently, the array_search function, has a bug i found. It will not return the first array
position! (exemple below)
$array = array();
array_push($array,'bob');
array_push($array,'pete');
array_push($array,'andy');
array_push($array,'jib');
if (array_search('pete', $array) != Null) echo 'found'; else echo 'not
found';
// returns "found"
if (array_search('bob', $array) != Null) echo 'found'; else echo 'not
found';
// returns "not found" !?!
// this could be because of the array_push function, but it can be fixed with the following:
$array = array(0 => 'not relevant');
array_push($array,'bob');
array_push($array,'pete');
array_push($array,'andy');
array_push($array,'jib');
if (array_search('bob', $array) != Null) echo 'found'; else echo 'not
found';
// returns "found"
----
Server IP: 83.137.20.120
Probable Submitter: 82.92.27.234
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/71293
Del: integrated -- https://master.php.net/note/delete/71293/integrated
Del: useless -- https://master.php.net/note/delete/71293/useless
Del: bad code -- https://master.php.net/note/delete/71293/bad+code
Del: spam -- https://master.php.net/note/delete/71293/spam
Del: non-english -- https://master.php.net/note/delete/71293/non-english
Del: in docs -- https://master.php.net/note/delete/71293/in+docs
Del: other reasons-- https://master.php.net/note/delete/71293
Reject -- https://master.php.net/note/reject/71293
Search -- https://master.php.net/manage/user-notes.php