This question already has an answer here:
这个问题在这里已有答案:
- comparing arrays in php, without caring for the order 5 answers
比较php中的数组,而不关心5个答案的顺序
I'm trying solving a problem where i need to check if the arrays are same no matter how they are sorted i cannot use sorting because it add extra over head to time this function is taking in answering.
我正在尝试解决一个问题,我需要检查数组是否相同,无论它们如何排序我都不能使用排序,因为它增加了额外的时间,这个功能正在接受回答。
I am currently using array_diff_assoc
我目前正在使用array_diff_assoc
$arr1 = array(1,2,3);
$arr2 = array(3,2,1);
$result = array_diff_assoc($arr1,$arr2);
print_r($result);
Array ( [0] => 1 [2] => 3 ) But the above arrays are same!! The human way.
数组([0] => 1 [2] => 3)但是上面的数组是一样的!!以人为本。
Any idea for comparing two arrays.
任何比较两个数组的想法。
1 个解决方案
#1
0
Well interpreter is not human right ? ;)
那么口译员不是*吗? ;)
Even if you do a simple var_dump($arr1==$arr2)
on your existing array, it will return false.
即使你在现有数组上执行一个简单的var_dump($ arr1 == $ arr2),它也会返回false。
This below code returns true !
以下代码返回true!
$arr1 = array(1,2,3);
$arr2 = array(2=>3,1=>2,0=>1);//position is same as yours., i've just set a key
var_dump($arr1==$arr2); //true
#1
0
Well interpreter is not human right ? ;)
那么口译员不是*吗? ;)
Even if you do a simple var_dump($arr1==$arr2)
on your existing array, it will return false.
即使你在现有数组上执行一个简单的var_dump($ arr1 == $ arr2),它也会返回false。
This below code returns true !
以下代码返回true!
$arr1 = array(1,2,3);
$arr2 = array(2=>3,1=>2,0=>1);//position is same as yours., i've just set a key
var_dump($arr1==$arr2); //true