Parsing the difference between Array_merge and Array+array in PHP _php skills

Source: Internet
Author: User
Array_merge is the key that discards the original number, while the key in the string is preserved, and then a new array is formed, regardless of whether the key name is the same or not, unless the key name and value are the same and must be a string in the form of a key to merge. And Array+array is no matter what your situation is, it will only first put the previous array of data into the newly generated array, and then see whether the second array is more than the first number of arrays, many added, it is only a few numbers, but this situation it will add in: $a = array (' d ' => ' Aass ', ' e ' => ' adsdfd ', ' ASD ' => ' ASDSDD ', ' ddfg ' => ' dssdf ');
Copy Code code as follows:

$b = Array (' d ' => ' adddd ', ' adsdfd ', ' asdfsddddd ', ' d ' => ' Aass ');
$d = $a + $b;
$e = Array_merge ($a, $b);
Var_dump ($d);
Var_dump ($e);

Print:
Array
' d ' => string ' Aass ' (length=4)
' E ' => string ' ADSDFD ' (length=6)
' ASD ' => string ' ASDSDD ' (length=6)
' DDFG ' => string ' dssdf ' (length=5)
0 => string ' adsdfd ' (length=6)
1 => string ' asdfsddddd ' (length=10)
Array
' d ' => string ' Aass ' (length=4)
' E ' => string ' ADSDFD ' (length=6)
' ASD ' => string ' ASDSDD ' (length=6)
' DDFG ' => string ' dssdf ' (length=5)
0 => string ' adsdfd ' (length=6)
1 => string ' asdfsddddd ' (length=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.