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:

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.

About the Author

has written 32 stories on this site.

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!

*

Copyright © 2017 Programmer to Programmer- A website for web programming and mobile application programming tutorials.
Wordpress themes