PHP array 的加法操作代码
作者:bea
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"); $
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:
";
var_dump($c);
$c = $b + $a; // Union of $b and $a
echo "Union of $b and $a:
";
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
$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:
";
var_dump($c);
$c = $b + $a; // Union of $b and $a
echo "Union of $b and $a:
";
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 MemCached高级缓存配置图文教程
- PHP Array交叉表实现代码
- php垃圾代码优化操作代码
- PHP MemCached 高级缓存应用代码
- phpMyAdmin 链接表的附加功能尚未激活的问题
- PHP合并数组+与array_merge的区别分析
- PHP自定义函数收代码
- 无法在发生错误时创建会话,请检查 PHP 或网站服务器日志,并正确配置 PHP 安装最快的解决办法
- PHP5中使用PDO连接数据库的方法
- PHP网站安装程序制作的原理、步骤、注意事项和示例代码
- PHP Stream_*系列函数
- php下目前为目最全的CURL中文说明
- php feof用来识别文件末尾字符的方法
- apache+php+mysql安装配置方法小结
- PHP 作用域解析运算符(::)
- PHP中的integer类型使用分析
- PHP中的float类型使用说明
- PHP中的array数组类型分析说明
- ionCube 一款类似zend的PHP加密/解密工具