Differences between array merge and + in PHP

Source: Internet
Author: User
Tags creative commons attribution

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.