How can I get case-sensitive return from array_intersect()

后端 未结 1 670
灰色年华
灰色年华 2021-01-06 07:06

I have two arrays and I need to compare that and return matched value from array1. Please refer my code below,

$array1 = array(\"a\" => \"Green\", \"Red\"         


        
相关标签:
1条回答
  • 2021-01-06 08:03

    This is because you put all values to lowercase. Just change to array_uintersect() and use strcasecmp() as callback function to compare them case-insensitive, like this:

    $result = array_uintersect($array1, $array2, "strcasecmp");
    

    output:

    Array ( [a] => Green [0] => Red )
    
    0 讨论(0)
提交回复
热议问题