PHP case-insensitive in_array function

前端 未结 11 591
故里飘歌
故里飘歌 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:51

    • in_array accepts these parameters : in_array(search,array,type)
    • if the search parameter is a string and the type parameter is set to TRUE, the search is case-sensitive.
    • so in order to make the search ignore the case, it would be enough to use it like this :

    $a = array( 'one', 'two', 'three', 'four' );

    $b = in_array( 'ONE', $a, false );

提交回复
热议问题