Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-13 10:06:21
Original
1244 people have browsed it

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;>
Copy after login

The output results are as follows:

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

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;>
Copy after login

The output results are as follows:

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

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:...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template