note 20707 deleted from function.array-search by didou
| From: | didou@php.net | Date: | Wed, 21 May 2003 13:32:54 +0000 |
| Subject: | note 20707 deleted from function.array-search by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48737@lists.php.net to get a copy of this message | ||
Note Submitter: chen.avinadav@vbulletin.com
----
> 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;
}