Is there a better way to get a key from an array if it is found in case-insensitive search?
The logic of the code I need is like below:
<?php
$search = "foo";
$array = array('Foo' => 1, 'Boo' => 2);
if (array_key_exists($search, array_map('strtolower', $array)))
return "Foo";
?>
Approach I would like to improve:
<?php
if (array_key_exists($search, array_map('strtolower', $array)))
{
foreach($array as $k => $v)
{
if ($search == strtolower($k))
return $k;
}
unset ($k, $v);
}
?>