Search code examples
phparraysfilteringcase-insensitive

Case-insensitive version of array_search()


I have an array like this:

$array = ['oooo', 'no', 'mmmm', 'yes']; 

I'd like to search for a word "yes". I know about array_search(), but I'd like to match "yes", "Yes" and "YES" as well.

How can I do this?


Solution

  • array_search(strtolower($search), array_map('strtolower', $array));