PHP 数组运算符

+运算符是把两个数组联合起来,如果相加的两个数组的键名一样,则左边的会覆盖右边的

$a = array("a" => "apple", "b" => "banana");
$b = array("a" => "pear", "b" => "strawberry", "c" => "cherry");

$c = $a + $b; 
var_dump($c);
//打印出来的结果
array(3) {
  ["a"]=>
  string(5) "apple"
  ["b"]=>
  string(6) "banana"
  ["c"]=>
  string(6) "cherry"
}

评论 抢沙发

表情