PHP case-insensitive in_array function

前端 未结 11 621
故里飘歌
故里飘歌 2020-11-29 19:52

Is it possible to do case-insensitive comparison when using the in_array function?

So with a source array like this:

$a= array(
 \'one\'         


        
11条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 20:35

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

    Source: php.net in_array manual page.

提交回复
热议问题