PHP array 的加法操作代码
发布时间:2020-12-13 05:45:56 所属栏目:PHP教程 来源:网络整理
导读: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 = a
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中。 我错了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 浅析php中实现多线程
- PHP中::、->、self、$this操作符
- Ajax PHP JavaScript MySQL实现简易无刷新在线聊天室
- PHP中的str_repeat函数在JavaScript中的实现
- php – 设置lable到zend框架中createElement方法创建的元素
- php – 如何在其他控制器中暂停电子邮件(在任务中)并发送普
- php – Facebook Open Graph:旧Facebook新闻Feed和新Faceb
- php – 在默认的joomla 3.1.1注册表单中添加自定义字段
- 配置 – 用另一个文件覆盖php-fpm池配置值
- PHP编程:php随机抽奖实例分析