Case insensitive array search

I have an array like this:

$array = Array ( 0 => 'oooo', 1 => 'no', 2 => 'mmmm', 3 => 'yes' ); 

I would like to find the word yes. I know about array_search() , but I would like to combine yes, yes and yes.

How can i do this?

+49
arrays php
Nov 12 2018-10-18
source share
3 answers
 array_search(strtolower($search), array_map('strtolower', $array)); 
+119
Nov 13 2018-10-11T00:
source share

You can use in_array() instead of array_search() .

 $response = in_array('yes', array_map('strtolower', $array)); 
+1
Apr 13 '17 at 19:19
source share

Edit: Sorry, I see this for values, see http://php.net/manual/en/function.array-change-key-case.php#88648




For keys:

 $a = array('YES', 'yes', 'Yes'); $b = array_change_key_case($a, CASE_LOWER); $f = array_search(strtolower($search), $b); 
0
Nov 12 '10 at 19:14
source share



All Articles