note 68184 deleted from function.in-array by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:59:32 +0000 |
| Subject: | note 68184 deleted from function.in-array by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134490@lists.php.net to get a copy of this message | ||
Note Submitter: emailfire at gmail dot com
----
This function allows you to use regular expressions to search the array:
<?php
function preg_array($pattern, $array)
{
$match = 0;
foreach ($array as $key => $value)
{
if (preg_match($pattern, $value))
{
$match = 1;
break;
}
}
return ($match == 1) ? true : false;
}
?>
An example:
<?php
$colors = array('red', 'green', 'blue');
if (preg_array("/green/i", $colors)) {
echo "Match found!";
}
else {
echo "Match not found!";
}
?>