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 :...