Check if two arrays have the same values

后端 未结 9 1385
既然无缘
既然无缘 2020-12-15 02:45
[2,5,3]    

[5,2,3]

They are equal because they have the same values, but not in the same order. Can I find out that without using a foreach loop

9条回答
  •  暖寄归人
    2020-12-15 03:21

    The best way will be using array_diff http://php.net/manual/en/function.array-diff.php

    $arr1 = [2,5,3];
    $arr2 = [5,2,3];
    
    $isEqual = array_diff($arr1,$arr2) === array_diff($arr2,$arr1);
    

提交回复
热议问题