note 25948 added to function.array-search
| From: | ryan at wonko dot com | Date: | Sat, 12 Oct 2002 07:27:13 +0000 |
| Subject: | note 25948 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37969@lists.php.net to get a copy of this message | ||
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):
/**
* 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;
}
--
http://www.php.net/manual/en/function.array-search.php
http://master.php.net/manage/user-notes.php?action=edit+25948
http://master.php.net/manage/user-notes.php?action=delete+25948
http://master.php.net/manage/user-notes.php?action=reject+25948