preg_grep

array preg_grep(string pattern, array strings) 
pattern Perl regex pattern to match
strings Array of strings to search

Returns the elements of the input array that match the specified pattern.

Returns:

Array of elements matched

Description:

This function traverses the input array, testing all elements against the supplied pattern. If a match is found, the matching element is returned as part of the array containing all matches.

Since PHP version 4.0.4, the elements in the result array are indexed by the keys they were associated with in the input array. That is, if the element with key 23 in the input array matches, it will be accessible as $outputarray[23]. If this behavior is not desirable, the result array can be run through ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.