PHP array 的加法操作代码

yipeiwu_com6年前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的时候,才知道

复制代码 代码如下:

<?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中。
我错了。

相关文章

php用户登录之cookie信息安全分析

本文实例讲述了php用户登录之cookie信息安全。分享给大家供大家参考,具体如下: 大家都知道用户登陆后,用户信息一般会选择保存在cookie里面,因为cookie是保存客户端,并且c...

phpMyadmin 用户权限中英对照

数据: SELECT:允许读取数据。 INSERT:允许插入和替换数据。 UPDATA:允许更改数据。 DELETE:允许删除数据。 FILE:允许从文件中导入数据以及将数据导出至文件。...

php使用memcoder将视频转成mp4格式的方法

本文实例讲述了php使用memcoder将视频转成mp4格式的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:<?php convertTo( "som...

php网站来路获取代码(针对搜索引擎)

复制代码 代码如下:function get_referer(){ $se = 0; $url = $_SERVER["HTTP_REFERER"]; //获取完整的来路URL $str...

APACHE的AcceptPathInfo指令使用介绍

学习zfdemo的时候提到设置 AcceptPathInfo 指令. 有时我们在做虚拟静态化或者让路径看起来很漂亮的时候,可能会看到http://www.example.com/inde...