有两个数组
$a = array('aaa','bbb','ddd','aaa');
$b = array('aaa','ddd','aaa','bbb');
$b = array('aaa','ddd','aaa','bbb');
如何比较这两个数组是否相等,前提是不能使用sort()之类的内置函数进行排序。
如果一定要使用内置函数,哪一个排序函数速度最快???
++++++++++++++++++++++++++++++++++++++++++++++
$a = array('aaa','bbb','ddd','aaa');
$b = array('aaa','ddd','aaa','bbb');
$c = array_diff($a, $b);
print_r($c);//输出array()
$b = array('aaa','ddd','aaa','bbb');
$c = array_diff($a, $b);
print_r($c);//输出array()
$a = array('aaa1','bbb','ddd','aaa');
$b = array('aaa','ddd','aaa','bbb');
$c = array_diff($a, $b);
print_r($c);//输出array('aaa1')
$b = array('aaa','ddd','aaa','bbb');
$c = array_diff($a, $b);
print_r($c);//输出array('aaa1')
++++++++++++++++++++++++++++++++++++++++++++++
至于两个数组相同,不清楚怎么说的,是键值相同,还是键值与键名都相同?
如果单纯地比较键值,用1楼的就行了。。
如果单纯地比较键值,用1楼的就行了。。
++++++++++++++++++++++++++++++++++++++++++++++
array_diff 可行,如果返回的是空数组即说明,2个数组相同!