Array OperatorsExampleNameResult$a + $bUnionUnion of $a and $b.$a == $bEquality&true; if $a and $b have the same key/value pairs.$a === $bIdentity&true; if $a and $b have the same key/value pairs in the same
order and of the same types.$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 returns the right-hand array appended
to the left-hand array; for keys that exist in both arrays, the elements
from the left-hand array will be used, and the matching elements from the
right-hand array will be ignored.
Array Append Operator
"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);
$a += $b; // Union of $a += $b is $a and $b
echo "Union of \$a += \$b: \n";
var_dump($a);
?>
]]>
&example.outputs;
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"
}
Union of $a += $b:
array(3) {
["a"]=>
string(5) "apple"
["b"]=>
string(6) "banana"
["c"]=>
string(6) "cherry"
}
]]>
Elements of arrays are equal for the comparison if they have the
same key and value.
Comparing arrays
"banana", "0" => "apple");
var_dump($a == $b); // bool(true)
var_dump($a === $b); // bool(false)
?>
]]>
&reftitle.seealso;
Array typeArray functions