Home  >  Article  >  Backend Development  >  How to add two arrays in php, how to add arrays in php_PHP tutorial

How to add two arrays in php, how to add arrays in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:06:211221browse

How to add two arrays in php, how to add arrays in php

The example in this article describes how to add two arrays in PHP. Share it with everyone for your reference. The details are as follows:

Example 1:

<&#63;php
$arr1 = array("a"=>"朝阳区","b"=>"海淀区");
$arr2 = array("h"=>"西城区","a"=>"东城区","b"=>"丰台区");
$arr = $arr1 + $arr2;
echo "<pre class="brush:php;toolbar:false">";
print_r($arr);
&#63;>

The output results are as follows:

Array
(
  [a] => 朝阳区
  [b] => 海淀区
  [h] => 西城区
)

Change the order of addition, Example 2:

<&#63;php
$arr1 = array("a"=>"朝阳区","b"=>"海淀区");
$arr2 = array("h"=>"西城区","a"=>"东城区","b"=>"丰台区");
$arr = $arr2 + $arr1;
echo "<pre class="brush:php;toolbar:false">";
print_r($arr);
&#63;>

The output results are as follows:

Array
(
  [h] => 西城区
  [a] => 东城区
  [b] => 丰台区
)

Comparing the above two examples, we can see:

(1) The addition is the following array, which is added to the previous array;
(2) If the key names are the same, they will not be overwritten.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/959114.htmlTechArticleHow to implement the addition of two arrays in php, the implementation of array addition in php This article describes the implementation of two arrays in php Addition method. Share it with everyone for your reference. The details are as follows: Example 1:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn