Skip to content

Instantly share code, notes, and snippets.

@sepehr
Created August 27, 2013 09:12
Show Gist options
  • Save sepehr/6351397 to your computer and use it in GitHub Desktop.
Save sepehr/6351397 to your computer and use it in GitHub Desktop.
PHP: Case-insensitive in_array()
<?php
/**
* 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));
}
@adamcameron
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!

@raph8888
Copy link

raph8888 commented Dec 8, 2017

Sweet.

@bls1999
Copy link

bls1999 commented Dec 11, 2017

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

@ZamBoyle
Copy link

ZamBoyle commented Apr 19, 2021

Very clever use of the callback parameter. :)

@hembachrterran
Copy link

@Florian418
Copy link

Thx ♥

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