Possible Duplicate:
PHP compare array
I have to compare two arrays in php and print the out put if the both arrays are same but can order elements in any way
ie
$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
Please help
var_dump(sizeof(array_diff($array1, $array2)) === 0);
function compareArrays($array1, $array2) {
foreach ($array2 as $currentValue) {
if (!in_array($currentValue, $array1) {
return false;
}
}
return true;
}