note 12045 added to function.array-search.php
| From: | kerry at lothrop dot de | Date: | Tue, 20 Mar 2001 10:06:57 +0000 |
| Subject: | note 12045 added to function.array-search.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12577@lists.php.net to get a copy of this message | ||
Note that in the above example you cannot tell the difference between "not found" and
"element 0 found" which means that you have to check this beforehand with the in_array
function.
If you have a PHP4 which doesn't have this function, try defining it yourself with this
function:
function array_search ($needle, $haystack, $strict = FALSE) {
for ($int = 0; $int < count($haystack); ++$int) {
if ($strict) {
if ($haystack[$int] === $needle) return $int;
}
else {
if ($haystack[$int] == $needle) return $int;
}
}
return FALSE;
}
http://www.php.net/manual/en/function.array-search.php