This article mainly introduces the php method for adding two arrays. The example analyzes the php array operator + usage skills and has some reference value, for more information about how to add two arrays in php, see the example in this article. 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.