note 68184 added to function.in-array
| From: | emailfire at gmail dot com | Date: | Mon, 17 Jul 2006 15:46:29 +0000 |
| Subject: | note 68184 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114848@lists.php.net to get a copy of this message | ||
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!";
}
?>
----
Server IP: 85.116.0.130
Probable Submitter: 86.136.185.164
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/note/edit/68184
Del: integrated -- http://master.php.net/note/delete/68184/integrated
Del: useless -- http://master.php.net/note/delete/68184/useless
Del: bad code -- http://master.php.net/note/delete/68184/bad+code
Del: spam -- http://master.php.net/note/delete/68184/spam
Del: non-english -- http://master.php.net/note/delete/68184/non-english
Del: in docs -- http://master.php.net/note/delete/68184/in+docs
Del: other reasons-- http://master.php.net/note/delete/68184
Reject -- http://master.php.net/note/reject/68184
Search -- http://master.php.net/manage/user-notes.php