PHP array 的加法操作代碼
更新時間:2010年07月24日 01:17:54 作者:
PHP array 的加法操作過程中的一個問題,大家可以繼續(xù)往下看。
The + operator appends elements of remaining keys from the right handed array to the left handed, whereas duplicated keys are NOT overwritten.
今天 再次看 php manual的時候,才知道
復(fù)制代碼 代碼如下:
<?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:
復(fù)制代碼 代碼如下:
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中的元素直接復(fù)制到$a中。
我錯了。
相關(guān)文章
PHP stream_context_create()作用和用法分析
創(chuàng)建并返回一個文本數(shù)據(jù)流并應(yīng)用各種選項,可用于fopen(),file_get_contents()等過程的超時設(shè)置、代理服務(wù)器、請求方式、頭信息設(shè)置的特殊過程。2011-03-03
PHP實現(xiàn)陽歷到農(nóng)歷轉(zhuǎn)換的類實例
這篇文章主要介紹了PHP實現(xiàn)陽歷到農(nóng)歷轉(zhuǎn)換的類,實例分析了陽歷轉(zhuǎn)換到陰歷的原理與實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03
PHP中實現(xiàn)中文字符進制轉(zhuǎn)換原理分析
中文字符編碼研究系列第四期,PHP實現(xiàn)中文字符進制轉(zhuǎn)換原理分析,主要討論中文漢字轉(zhuǎn)換為十進制和十六進制的方法,并掌握轉(zhuǎn)換原理應(yīng)用于實際開發(fā)。本文以GBK編碼字符為例,討論GBK編碼的字符轉(zhuǎn)換原理2011-12-12
PHP實現(xiàn)獲取毫秒時間戳的方法【使用microtime()函數(shù)】
這篇文章主要介紹了PHP實現(xiàn)獲取毫秒時間戳的方法,結(jié)合實例形式分析了php使用microtime()函數(shù)獲取、轉(zhuǎn)換毫秒級時間戳的相關(guān)操作技巧,需要的朋友可以參考下2019-03-03

