PHP: Built-in function to check whether two Array values are equal ( Ignoring the Order)

后端 未结 7 882
刺人心
刺人心 2020-12-30 01:34

Is there a built-in function for PHP for me to check whether two arrays contain the same values ( order not important?).

For example, I want a function that returns

7条回答
  •  长发绾君心
    2020-12-30 02:02

    You only need to compare one-way using array_diff() and use count() for the inverted relationship.

    if (count($a1) == count($a2) && !array_diff($a1, $a2)) {
        // equal arrays
    }
    

提交回复
热议问题