Differences between PHP arraymerge and +: PHP array_merge converts the value to 0, 1, 2..., even if it is forcibly converted to a string. example-use array_merge & lt ;? Php $ a1array (??? 9 & gt; 0 ,??? 311 & gt; 1. differences between array merge and + in PHP
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
$ 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
$ A1 = array (
??? '9 '???? => '0 ',
??? '123 '?? => '1 ',
??? 'Happy '?? => '2 ',
??? '2009a' => '3'
);
$ A2 = array (
??? '123 '? => '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.