How to perform case insensitive array search in php?
Searching is a usual and regular task in programming. Letters case sensitivity is a problematic in searching. Hence, both search string and array string should be converted into same case before searching. Otherwise searching would return the empty result. Here is how to do it:
$array = array("apple","mango","banana"); $searchString = "Apple"; array_search(strtolower($searchString), array_map('strtolower', $array));
As shown above, search string is converted into lowercase and all the items of an array are converted to lowercase with array_map function and finally array_search is done. Alternatively, same can be done with converting search string and array into uppercase using strtoupper function.
Hope, it helps. If helped, please do not forget to comment below. Thanks.
Very Good Post
Keep it
L