preg_grep() function searches all elements of input_array, returning all elements matching the regexp pattern.
Its syntax is: array preg_grep (string pattern, array input_array)
<?
$foods = array("pasta", "steak", "fish", "potatoes");
$p_foods = preg_grep("/p(\w+)/", $foods);
$x = 0;
while ($x < sizeof($p_foods)) :
print $p_foods[$x]. "<br>";
$x++;
endwhile;
?>
Related examples in the same category