note 20707 added to function.array-search
| From: | chen dot avinadav at vbulletin dot com | Date: | Sat, 13 Apr 2002 08:15:30 +0000 |
| Subject: | note 20707 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29187@lists.php.net to get a copy of this message | ||
> for those with php <= 4.04, copy this function in the source or
> your code.
While that function is correct, it will always return the first key in the array its value matches
needle. (Unlike the original function, which returns the last key.)
The correct function would look more like this:
function array_search($needle, $haystack) {
$match = false;
foreach ($haystack as $key => $value) {
if ($key == $needle) {
$match = $key;
}
}
return $match;
}
--
http://www.php.net/manual/en/function.array-search.php
http://master.php.net/manage/user-notes.php?action=edit+20707
http://master.php.net/manage/user-notes.php?action=delete+20707
http://master.php.net/manage/user-notes.php?action=reject+20707