当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP array 的加法操作代码

PHP array 的加法操作代码

2019年04月28日  | 移动技术网IT编程  | 我要评论

何者为卿狂txt,天天亦铭,情侣内衣

the + operator appends elements of remaining keys from the right handed array to the left handed, whereas duplicated keys are not overwritten.

今天 再次看 php manual的时候,才知道

复制代码 代码如下:

<?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 will print the following:
union of $a and $b:
复制代码 代码如下:

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(10) "strawberry"
["c"]=>
string(6) "cherry"
}

原来,我的理解就是。直接把$b中的元素直接复制到$a中。
我错了。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网