Axel Amthor
Axel Amthor

Reputation: 11106

Determine if two flat indexed array are equal

Supposed we have:

$arr1 = array("a", "b");
$arr2 = array("a", "b");

and arrays are always sorted. Is this true:

if ( $arr1 === $arr2 )
{
     echo "condition met";
}

Upvotes: 0

Views: 41

Answers (2)

George G
George G

Reputation: 7705

($arr1 == $arr2); // TRUE when both  have the same key/value pairs.
($arr1 === $arr2); // TRUE when both have the same key/value pairs in the same order and of the same types.

Upvotes: 1

Charlotte Dunois
Charlotte Dunois

Reputation: 4680

You can compare two (and more) arrays with array_diff() and look for an empty array, in your case.

$diff = array_diff($arr1, $arr2);
if(empty($diff)) {
    echo "condition met";
}

Upvotes: 1

Related Questions