Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
Array Operators

Array Operators

Table 15-8. Array Operators

ExampleNameResult
$a + $bUnionUnion of $a and $b.
$a == $bEqualityTRUE if $a and $b have the same key/value pairs.
$a === $bIdentityTRUE if $a and $b have the same key/value pairs in the same order and of the same types.
$a != $bInequalityTRUE if $a is not equal to $b.
$a <> $bInequalityTRUE if $a is not equal to $b.
$a !== $bNon-identityTRUE if $a is not identical to $b.

The + operator appends the right handed array to the left handed, whereas duplicated keys are NOT overwritten.

&#60;?php
$a = array("a" =&#62; "apple", "b" =&#62; "banana");
$b = array("a" =&#62; "pear", "b" =&#62; "strawberry", "c" =&#62; "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);
?&#62;

When executed, this script will print the following:
Union of $a and $b:
array(3) {
  ["a"]=&#62;
  string(5) "apple"
  ["b"]=&#62;
  string(6) "banana"
  ["c"]=&#62;
  string(6) "cherry"
}
Union of $b and $a:
array(3) {
  ["a"]=&#62;
  string(4) "pear"
  ["b"]=&#62;
  string(10) "strawberry"
  ["c"]=&#62;
  string(6) "cherry"
}

Elements of arrays are equal for the comparison if they have the same key and value.

Example 15-6. Comparing arrays

&#60;?php
$a = array("apple", "banana");
$b = array(1 =&#62; "banana", "0" =&#62; "apple");

var_dump($a == $b); // bool(true)
var_dump($a === $b); // bool(false)
?&#62;

See also the manual sections on the Array type and Array functions.