Introduction: This is a detailed page of the difference between array merge and + of PHP. It introduces related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 334781 'rolling = 'no'>
PHP's array_merge will convert the value to 0, 1, 2..., even if it is forcibly converted to a string.
Example-use array_merge
<? PHP
$ A1 = array (
'9' => '0 ',
'20140901' => '1 ',
'Happy '=> '2 ',
'2009a' => '3 ');
$ A2 = array (
'20140901' => '11 ',
'Christmas '=> '22 ',
'111a '=> '33 ');
$ Amerge = array ();
$ Amerge = array_merge ($ A1, $ A2 );
Print_r ($ amerge );
?>
Output result
Array
(
[0] => 0
[1] => 1
[Happy] => 2
[2009a] => 3
[2] => 11
[Christmas] => 22
[111a] => 33
)
On the official website (array_merge
),You can use "+" to merge and retain the key (hash, index) value.
Example-use + merge
<? PHP
$ A1 = array (
'9' => '0 ',
'20140901' => '1 ',
'Happy '=> '2 ',
'2009a' => '3'
);
$ A2 = array (
'20140901' => '11 ',
'Christmas '=> '22 ',
'111a '=> '33'
);
$ Amerge = array ();
$ Amerge = $ A1 + $ A2;
Print_r ($ amerge );
?>
Output result
Array
(
[9] => 0
[311] => 1
[Happy] => 2
[2009a] => 3
[1, 2009] => 11
[Christmas] => 22
[111a] => 33
)
Original website/reposted from:
Tsung Hao
This work, unless otherwise expressly stated, is licensed under
Creative Commons Attribution-submit Alike 3.0 unported license
.
More articles on "differences between array merge and + in PHP"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/334781.html pageno: 10.