簡介:這是PHP 的 array merge 與 + 號的區別的詳細頁面,介紹了和php,有關的知識、技巧、經驗,和一些php源碼等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=334781' scrolling='no'>
PHP 的 array_merge 會將 數值 變成 0, 1, 2..., 就算是強制轉換成字串也一樣.
範例 - 使用 array_merge
<?php
$a1 = array(
'9' => '0',
'311' => '1',
'快樂' => '2',
'2009a' => '3');
$a2 = array(
'2009' => '11',
'聖誕節' => '22',
'111a' => '33');
$amerge = array();
$amerge = array_merge($a1, $a2);
print_r($amerge);
?>
輸出結果
Array
(
[0] => 0
[1] => 1
[快樂] => 2
[2009a] => 3
[2] => 11
[聖誕節] => 22
[111a] => 33
)
於 官方網站查(array_merge
), 使用 "+" 就可以 merge, 而且會將 key(hash、index) 值保留.
範例 - 使用 + 合并
<?php
$a1 = array(
'9' => '0',
'311' => '1',
'快樂' => '2',
'2009a' => '3'
);
$a2 = array(
'2009' => '11',
'聖誕節' => '22',
'111a' => '33'
);
$amerge = array();
$amerge = $a1 + $a2;
print_r($amerge);
?>
輸出結果
Array
(
[9] => 0
[311] => 1
[快樂] => 2
[2009a] => 3
[2009] => 11
[聖誕節] => 22
[111a] => 33
)
原文網站 / 轉載自:
Tsung Hao
This work, unless otherwise expressly stated, is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License
.
“PHP 的 array merge 與 + 號的區別”的更多相關文章 》
愛J2EE關注Java邁克爾傑克遜視頻站JSON線上工具
http://biancheng.dnbcw.info/php/334781.html pageNo:10