源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP array 的加法操作代码

  • 时间:2021-09-05 17:00 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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的时候,才知道
[u]复制代码[/u] 代码如下:
<?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:
[u]复制代码[/u] 代码如下:
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中。 我错了。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部