加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

PHP array 的加法操作代码

发布时间:2020-05-25 20:51:30 所属栏目:PHP 来源:互联网
导读:PHP array 的加法操作过程中的一个问题,大家可以继续往下看。

The + operator appends elements of remaining keys from the right handed array to the left handed,whereas duplicated keys are NOT overwritten. 今天 再次看 php manual的时候,才知道
代码如下:$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中。
我错了。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读