可能重复:
PHP compare array
我必须在php中比较两个数组并打印输出,如果两个数组相同但可以以任何方式排序元素
即
$array1=array('a','p','p','l','e');
$array2=array('p','a','e','l');
--- This must return as success because all of the letters in array1 is there in array2
$array1=array('a','p','p','l','e','s');
$array2=array('p','a','e','l');
-- This must return false
$array1=array('a','p','p','l','e','s');
$array1=array('a','p','p','l','e','s');
-- This must return true
请帮忙
答案 0 :(得分:5)
var_dump(sizeof(array_diff($array1, $array2)) === 0);
答案 1 :(得分:1)
function compareArrays($array1, $array2) {
foreach ($array2 as $currentValue) {
if (!in_array($currentValue, $array1) {
return false;
}
}
return true;
}