PHP case-insensitive array search functions [duplicate]
Possible Duplicate:
PHP case-insensitive in_array function
Is it possible to do case-insensitive comparison when using the in_array
function?
So with a source array like this:
$a= array(
'one',
'two',
'three',
'four'
);
The following lookups would all return true:
in_array('one', $a);
in_array('ONE', $a);
in_array('fOUr', $a);
What function or set of functions would do the same? I don't think in_array
itself can do this. Because it is case sensitive.
If you want to apply strtolower on each element of the array, use array_map:
in_array(strtolower('ONE'), array_map('strtolower', $a));
精彩评论