preg_grep() function searches all elements of input_array, returning all elements matching the regexp pattern. : preg_grep « String « PHP






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

1.preg_grep
2.Using preg_grep()
3.Quickly finding lines that match a pattern