note 25948 deleted from function.array-search by felipe
| From: | felipe@php.net | Date: | Sun, 10 Feb 2008 13:11:38 +0000 |
| Subject: | note 25948 deleted from function.array-search by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-135967@lists.php.net to get a copy of this message | ||
Note Submitter: ryan at wonko dot com
----
If you'd rather search for values in an array that match a regular expression, this function
will do the trick (note that it returns the first index matched, not the last key matched as
array_search does):
<?php
/**
* Searches for a regex match in every value of a one-dimensional array.
*
* @param string $pattern POSIX-extended regular expression to match.
* @param array $haystack Array to search in.
* @return mixed Index of the first match, or FALSE if no match is found.
*/
function array_ereg($pattern, $haystack)
{
for($i = 0; $i < count($haystack); $i++)
{
if (ereg($pattern, $haystack[$i]))
return $i
}
return false;
}
?>