I was wondering if it was possible to use regex or preg_match() in array_seach() or array_keys_exist?
ie.
array_keys_exist($array,"^\d+$") to match all keys that are solely numeric characters
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t know whether it suits your needs exactly, but you should have a look at the
preg_grepfunction, which will check an array of strings against a regex and return all matching array elements. You could do same with the keys, by usingpreg_grepon the return value ofarray_keys.This is different from
array_search/array_key_existsin the respect, that these stop after they have found a match, because there may only be one match. With regex on the other hand there may be many elements satisfying the condition, sopreg_grepwill return all of them.