I don't know if this suits your needs, but you should look at the preg_grep function, which will check the array of strings against the regular expression and return all the relevant elements of the array. You can do the same with keys using preg_grep on the return value of array_keys .
This differs from array_search / array_key_exists in that they stop after they find a match, because there can only be one match. With a regular expression, on the other hand, there can be many elements satisfying the condition, so preg_grep will return them all.
NikiC source share