← All built-ins / preg_grep()
preg_grep()
preg_grep(...$args): mixed
Parameters
| Name | Type | Description |
|---|---|---|
| $pattern | string | /…/ pattern |
| $arr | array | array 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