Created
August 27, 2013 09:12
-
-
Save sepehr/6351397 to your computer and use it in GitHub Desktop.
PHP: Case-insensitive in_array()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); | |
} |
Sweet.
Not the hero we need, the hero we deserve. Well done, my friend.
Very clever use of the callback parameter. :)
Thx ♥
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!