← All built-ins / preg_grep()

preg_grep()

preg_grep(...$args): mixed

Parameters

NameTypeDescription
$patternstring/…/ pattern
$arrarrayarray of strings

Return value

The elements that match the pattern, re-indexed 0..n.

Example

$g = preg_grep("/^h/", ["holy", "php", "hi", "there"]);
echo implode(",", $g);
holy,hi

See also

array_filter()preg_match()