开发者

PHP case-insensitive array search functions [duplicate]

This question already has answers here: 开发者_开发问答 Closed 11 years ago.

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));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜