The + operator appends elements of remaining keys from the right handed array to the left handed, whereas duplicated keys are not overwritten.
Today, when I look at the PHP manual again, I know
Copy Code code as follows:
<?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);
?>
When executed, this script would print the following:
Union of $a and $b:
Copy Code code as follows:
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 (Ten) "Strawberry"
["C"]=>
String (6) "Cherry"
}
Originally, my understanding is that. Directly copy the elements in the $b directly into the $a.
I was wrong.