Well, we can do something like this:
if (count(array_diff(array_merge($a, $b), array_intersect($a, $b))) === 0) {
//they are the same!
}
The reason it works, is that array_merge
will make a big array that has all the elements of both $a
and $b
(all the elements that are in either $a
, $b
, or both). array_intersect
will create an array that has all the elements that are in both $a
and $b
only. So if they are different,, there must be at least one element that does not appear in both arrays...
Also note that sizeof
is not an actual function/construct, it's an alias. I'd suggest using count()
for clarity...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…