Accidentally found that many friends like to use array_ Diff (array1, array2) to determine whether two arrays are equal,
I use it occasionally myself
But today, in the process of writing code, I found that it was not accurate.
First, let’s take a look at the definition of this function (PHP manual)
Compare array1 with one or more other numbers and return the values in array1 but not in other arrays.
To be honest, it’s a bit awkward to read. Some friends like to read the code directly,
Through the code in the manual, we found that comparing two arrays can find the difference set and indirectly judge the equality
$array1 = array(“a” => “green”, “red”, “blue”, “red”);
$array2 = array(“b” => “green”, “yellow”, “red”);
$result = array_diff($array1, $array2);