note 68184 deleted from function.in-array by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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!";
}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.