在PHP中,当两个数组相加时,会把第二个数组的取值添加到第一个数组上,同时覆盖掉下标相同的值:
<?php $a = array("a" => "apple", "b" => "banana"); $b = array("a" => "pear", "b" => "strawberry", "c" => "cherry"); echo "a: </br> "; print_r($a); echo " </br> b: </br>"; print_r($b); $c = $a + $b; echo " </br>Union of \$a and \$b: </br>"; var_dump($c); $c = $b + $a; echo " </br>Union of \$b and \$a: </br>"; var_dump($c); $a += $b; echo " </br>Union of \$a += \$b: </br>"; var_dump($a); ?>
以上的输出结果为: