判断两个平面索引数组是否相等

问题描述 投票:0回答:2

假设我们有:

$arr1 = array("a", "b");
$arr2 = array("a", "b");

并且数组总是排序的。这是真的吗:

if ( $arr1 === $arr2 )
{
     echo "condition met";
}
php arrays comparison
2个回答
1
投票
($arr1 == $arr2); // TRUE when both  have the same key/value pairs.
($arr1 === $arr2); // TRUE when both have the same key/value pairs in the same order and of the same types.

1
投票

您可以使用 array_diff() 比较两个(或更多)数组,并根据您的情况查找空数组。

$diff = array_diff($arr1, $arr2);
if(empty($diff)) {
    echo "condition met";
}
© www.soinside.com 2019 - 2024. All rights reserved.