note 7095 modified in in_array by ronabop
| From: | ronabop@php.net | Date: | Wed, 21 Mar 2001 06:09:14 +0000 |
| Subject: | note 7095 modified in in_array by ronabop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12615@lists.php.net to get a copy of this message | ||
For those of you who are still using PHP 3 and those who want in_array to return the key for the
value being searched for, try the following alternative function:
function is_in_array($needle,$haystack) {
$needleFound = false;
$returnValue = false;
reset($haystack);
while ((list($key,$value) = each($haystack)) && !$needleFound) {
if ($needle == $value) {
$needleFound = true;
$returnValue = $key;
}
}
return $returnValue;
}
http://www.php.net/manual/in-array.php