Addition operation code of PHParray

Source: Internet
Author: User
There is a problem in the addition operation of PHParray. You can continue to look at it.

A problem in the addition operation of PHP array can be further viewed.

The + operator appends elements of remaining keys from the right handed array to the left handed, whereas duplicated keys are NOT overwritten.

I only know this when I read php manual again today.

The Code is as follows:


$ A = array ("a" => "apple", "B" => "banana ");
$ B = array ("a" => "pear", "B" => "strawberry", "c" => "cherry ");
$ C = $ a + $ B; // Union of $ a and $ B
Echo "Union of \ $ a and \ $ B: \ n ";
Var_dump ($ c );
$ C = $ B + $ a; // Union of $ B and $
Echo "Union of \ $ B and \ $ a: \ n ";
Var_dump ($ c );
?>


Bytes
When executed, this script will print the following:
Union of $ a and $ B:

The Code is as follows:


Array (3 ){
["A"] =>
String (5) "apple"
["B"] =>
String (6) "banana"
["C"] =>
String (6) "cherry"
}
Union of $ B and $:
Array (3 ){
["A"] =>
String (4) "pear"
["B"] =>
String (10) "strawberry"
["C"] =>
String (6) "cherry"
}


In the past, I understood the website space and the Hong Kong Space. Directly copy the elements in $ B to $.
I am wrong.

, Website Space

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.