views:

5693

answers:

4
+1  Q: 

PHP compare array

Is there anyway to compare arrays in php using an inbuilt function, short of doing some sort of loop?

$a1 = array(1,2,3);
$a2 = array(1,2,3);

if (array_are_same($a1, $a2)) {
// code here
}

Well you get the idea :D

+1  A: 

Just check $a1 == $a2 -- what's wrong with that?

Alex Martelli
+2  A: 
if ( $a == $b ) {
    echo 'We are the same!'
}
Alan Haggai Alavi
+3  A: 

http://php.net/array_diff

Jet
A: 

if(count($a1) == count($a2)){
$result= array_intersect($a1, $a2);
if(count($a1) == count($result))
echo 'the same';
else
echo 'a1 different than a2';
}else
echo 'a1 different than a2';