PHP case-insensitive in_array function
Snippet
A very nifty function for doing in_array() lookups in a case insensitive manner:
<?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));
}
//use is the same as with in_array() function, for example, check the file for a valid extension
$allowedExt = ['png','jpg','gif'];
$fileExt = 'Png';
if(in_arrayi($fileExt, $allowedExt)){
echo 'allowed';
} else {
echo 'not allowed';
}