Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case-insensitive array search

Tags:

arrays

php

I have an array like this:

$array = Array ( 0 => 'oooo',                  1 => 'no',                  2 => 'mmmm',                   3 => '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?

like image 807
Gowri Avatar asked Nov 12 '10 18:11

Gowri


People also ask

Is indexOf case insensitive?

Yes, the String. indexOf() methods are all case-sensitive.

Is In_array case sensitive?

The in_array() function searches an array for a specific value. Note: If the search parameter is a string and the type parameter is set to TRUE, the search is case-sensitive.

What does case insensitive mean?

case insensitive (not comparable) (computer science) Treating or interpreting upper- and lowercase letters as being the same.


1 Answers

array_search(strtolower($search), array_map('strtolower', $array)); 
like image 101
Halil Özgür Avatar answered Sep 21 '22 09:09

Halil Özgür