Skip to content

Instantly share code, notes, and snippets.

@sepehr
Created August 27, 2013 09:12
Show Gist options
  • Select an option

  • Save sepehr/6351397 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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

raph8888 commented Dec 8, 2017

Copy link
Copy Markdown

Sweet.

@bls1999

bls1999 commented Dec 11, 2017

Copy link
Copy Markdown

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

@ZamBoyle

ZamBoyle commented Apr 19, 2021

Copy link
Copy Markdown

Very clever use of the callback parameter. :)

@hembachrterran

Copy link
Copy Markdown

@Florian418

Copy link
Copy Markdown

Thx ♥

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