Array Operators
Table 10-7. Array Operators
ExampleNameResult$a + $bUnionUnion of $a and $b.$a == $bEquality TRUE if $a and $b have the same elements.$a === $bIdentity TRUE if $a and $b have the same elements in the same order.$a != $bInequality TRUE if $a is not equal to $b.$a <> $bInequality TRUE if $a is not equal to $b.$a !== $bNon-identity TRUE if $a is not identical to $b.The + operator appends the right handed array to the left handed, whereas duplicated keys are NOT overwritten.


<?php
$a = array("a" => "apple", "b" => "banana");
$b = array("a" => "pear", "b" => "strawberry", "c" => "cherry");
$c = $a + $b; // Union of $a and $b
echo "Union of \$a and \$b: \n";
var_dump($c);
$c = $b + $a; // Union of $b and $a
echo "Union of \$b and \$a: \n";
var_dump($c);
?>
Union of $a and $b:
array(3) {
["a"]=>
string(5) "apple"
["b"]=>
string(6) "banana"
["c"]=>
string(6) "cherry"
}
Union of $b and $a:
array(3) {
["a"]=>
string(4) "pear"
["b"]=>
string(10) "strawberry"
["c"]=>
string(6) "cherry"
}
Elements of arrays are equal for the comparison if they have the same key and value.


Example 10-2. Comparing arrays
<?php
$a = array("apple", "banana");
$b = array(1 => "banana", "0" => "apple");
var_dump($a == $b); // bool(true)
var_dump($a === $b); // bool(false)
?>
See also the manual sections on the Array type and Array functions.



