手机
当前位置:查字典教程网 >编程开发 >php教程 >PHP array 的加法操作代码
PHP array 的加法操作代码
摘要:The+operatorappendselementsofremainingkeysfromtherighthandedarraytothe...

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 array 的加法操作代码】相关文章:

PHP_Flame(Version:Progress)的原代码

类的另类用法--数据的封装

用在PHP里的JS打印函数

PHP通过API获取手机号码归属地

5.PHP的其他功能

PHP5的XML新特性

PHP实现将textarea的值根据回车换行拆分至数组

PHP的基本语法

PHP自动生成月历代码

PHP分页显示制作详细讲解

精品推荐
分类导航