Search Results
Parameters ¶ pattern The pattern to search for, as a string. array The input array. flags If set to PREG_GREP_INVERT, this function returns the elements of the input array that do not match the given pattern.
Definition and Usage The preg_grep() function returns an array containing only elements from the input that match the given pattern.
- Required. An array of strings
Jul 11, 2025 · Program 2: Take an example of PREG_GREP_INVERT, which is invert data instead of output numbers to be non-numeric values in php.
Returns the array consisting of the elements of the input array that match the given pattern. If flag is set to PREG_GREP_INVERT, this function returns the elements of the input array that do not match the given pattern.
preg_grep Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8 Return array entries that match the pattern
Mar 12, 2019 · Understand the preg_grep PHP function and related functions, and learn how to use them on your PHP website.
People also ask
What is preg_grep in PHP?
What does preg_grep() do?
What is a preg_grep_invert function?
What is preg_match in PHP?
Since PHP 4.0.4, the results returned by preg_grep () are indexed using the keys from the input array. If this behavior is undesirable, use array_values () on the array returned by preg_grep () to reindex the values.
