,因爲他們有不同的密鑰
$arr1 = array (0 => "apple", 1 => "banana");
$arr2 = array ("banana" => "banana", "apple" => "apple");
您可以使用array_diff
if(!array_diff($arr1, $arr2))
{
// They are the same
}
您可以使用array_intersect
if(count($arr1) == count(array_intersect($arr1, $arr2)))
{
// They are the same ;
}
可使用數組array_filter
if(array_filter($arr2,function($var)use($arr1){return !in_array($var,$arr1);}))
{
// They are the same ;
}
您可以使用array_values
$arr2 = array_values($arr2);
sort($arr1);sort($arr2); //sort to make sure they are in the same position
if($arr1 === $arr2)
{
// They are the same
}