Php implements the method of adding two arrays. php implements the array addition _ PHP Tutorial

Source: Internet
Author: User
Php adds two arrays, and php adds arrays. Php implements the method of adding two arrays. php implements the addition of arrays. This article describes how php can add two arrays. Share it with you for your reference. Example 1: php adds two arrays. php adds arrays.

This example describes how to add two arrays in php. Share it with you for your reference. The details are as follows:

Instance 1:

<? Php $ arr1 = array ("a" => "Chaoyang district", "B" => "Haidian District"); $ arr2 = array ("h" => "Xicheng District ", "a" => "Dongcheng District", "B" => "Fengtai district"); $ arr = $ arr1 + $ arr2; echo"
";print_r($arr);?>

The output result is as follows:

Array ([a] => Chaoyang District [B] => Haidian District [h] => Xicheng District)

Change the order of addition, instance 2:

<? Php $ arr1 = array ("a" => "Chaoyang district", "B" => "Haidian District"); $ arr2 = array ("h" => "Xicheng District ", "a" => "Dongcheng District", "B" => "Fengtai district"); $ arr = $ arr2 + $ arr1; echo"
";print_r($arr);?>

The output result is as follows:

Array ([h] => Xicheng District [a] => Dongcheng District [B] => Fengtai District)

From the comparison between the two instances above, we can see that:

(1) add an array to the previous one;
(2) keys with the same name are not overwritten.

I hope this article will help you with php programming.

Examples in this article describes how to add two arrays in php. Share it with you for your reference. Example 1 :...

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.