Examples:
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?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 ); $a += $b ; // Union of $a += $b is $a and $b echo "Union of \$a += \$b: \n" ; var_dump( $a ); ?> |
Comparing arrays
Elements of arrays are equal for the comparison if they have the same key and value.
1 2 3 4 5 6 7 | <?php $a = array ( "apple" , "banana" ); $b = array (1 => "banana" , "0" => "apple" ); var_dump( $a == $b ); // bool(true) var_dump( $a === $b ); // bool(false) ?> |
Please login to continue.