Skip to content

Instantly share code, notes, and snippets.

Created August 27, 2013 09:12
  • Star 16 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
PHP: Case-insensitive in_array()
* Case-insensitive in_array() wrapper.
* @param mixed $needle Value to seek.
* @param array $haystack Array to seek in.
* @return bool
function in_arrayi($needle, $haystack)
return in_array(strtolower($needle), array_map('strtolower', $haystack));
Copy link

Thanks for publicising this. Was racking my brains how to do this, and didn't realise one could use built-in functions with array_ap. Nice one!

Copy link

raph8888 commented Dec 8, 2017


Copy link

bls1999 commented Dec 11, 2017

Not the hero we need, the hero we deserve. Well done, my friend.

Copy link

ZamBoyle commented Apr 19, 2021

Very clever use of the callback parameter. :)

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment