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 38 stories on this site.

One Comment on “How to perform case insensitive array search in php?”

  • Aayur wrote on 11 February, 2019, 2:57

    Very Good Post
    Keep it

Write a Comment

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


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