Home > PHP > Function > PCRE > preg_grep()

preg_grep()

preg_grep - Return array entries that match the pattern

Syntax

array preg_grep (string $pattern, array $input, int $flags)

Arguments

  • pattern - The pattern to search for, as a string.
  • input - The input array.
  • flags - If set to PREG_GREP_INVERT, this function returns the elements of the input array that do notmatch the given pattern.

Description

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

Version

PHP 4, 5

Return value

Returns an array indexed using the keys from the input array.