PHP.nl

preg_grep

preg_grep

Return array entries that match the pattern

 **preg_grep** string $pattern array $array int $flags

Returns the array consisting of the elements of the array that match the given . array``pattern

patternThe pattern to search for, as a string.

arrayThe input array.

flags If set to , this function returns the elements of the input array that do match the given . PREG_GREP_INVERTnotpattern

Returns an array indexed using the keys from the array, return.falseforfailure. array

Voorbeeld: example

<?php
$array = [ "4", M_PI, "2.74", 42 ];

// return all array elements containing floating point numbers
$fl_array = preg_grep("/^(\d+)?\.\d+$/", $array);

var_dump($fl_array);
?>

PCRE Patternspreg_quote``preg_match_all``preg_filter``preg_last_error