Showing posts with label case insensitive. Show all posts
Showing posts with label case insensitive. Show all posts

PHP in_array() Case Insensitive

A very nifty function to carry out a case insensitive in_array() search:



function in_array_case_insensitive($needle, $haystack)
{
return in_array( strtolower($needle), array_map('strtolower', $haystack) );
}



Easy, huh? Here's an example of it in use




$fileExtensionsArray = Array("php", "html", "ASP", "sql", "JSP");
$extension = "PHP";

if (in_array_case_insensitive($extension, $fileExtensionsArray))
{
echo "Yes, $extension is in array";
}
else
{
echo "No $extension is NOT in array";
}