PHP compare array

后端 未结 17 1771
萌比男神i
萌比男神i 2020-11-28 12:19

Is there anyway to compare arrays in php using an inbuilt function, short of doing some sort of loop?

$a1 = array(1,2,3);
$a2 = array(1,2,3);

if (array_are_         


        
17条回答
  •  失恋的感觉
    2020-11-28 13:16

    Conclusion from the commentary here:

    Comparison of array values being equal (after type juggling) and in the same order only:

    array_values($a1) == array_values($a2)
    

    Comparison of array values being equal (after type juggling) and in the same order and array keys being the same and in the same order:

    array_values($a1) == array_values($a2) && array_keys($a1) == array_keys($a2)
    

提交回复
热议问题