PHP - Check if two arrays are equal

后端 未结 15 2077
说谎
说谎 2020-11-22 11:26

I\'d like to check if two arrays are equal. I mean: same size, same index, same values. How can I do that?

Using !== as suggested by a user, I expect th

15条回答
  •  旧时难觅i
    2020-11-22 11:49

    $arraysAreEqual = ($a == $b); // TRUE if $a and $b have the same key/value pairs.
    $arraysAreEqual = ($a === $b); // TRUE if $a and $b have the same key/value pairs in the same order and of the same types.
    

    See Array Operators.

    EDIT

    The inequality operator is != while the non-identity operator is !== to match the equality operator == and the identity operator ===.

提交回复
热议问题