Home > php教程 > php手册 > php实现两个数组相加的方法

php实现两个数组相加的方法

WBOY
Release: 2016-06-06 20:10:04
Original
1096 people have browsed it

这篇文章主要介绍了php实现两个数组相加的方法,实例分析了php的数组运算符+的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了php实现两个数组相加的方法。分享给大家供大家参考。具体如下:

实例1:

"朝阳区","b"=>"海淀区"); $arr2 = array("h"=>"西城区","a"=>"东城区","b"=>"丰台区"); $arr = $arr1 + $arr2; echo "

";
print_r($arr);
?>

<p>输出结果如下:</p>
<p>

Array
(
  [a] => 朝阳区
  [b] => 海淀区
  [h] => 西城区
)
</p>
<p>改变相加的顺序,实例2:</p>
<p>

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

<p>输出结果如下:</p>
<p>

Array
(
  [h] => 西城区
  [a] => 东城区
  [b] => 丰台区
)
</p>
<p>从上面两个实例比较,可以看出:</p>
<p>(1)相加是后面一个数组,加入到前面一个数组中;<br>
(2)键名相同时,不会被覆盖。</p>
<p>希望本文所述对大家的php程序设计有所帮助。</p>
,


Copy after login
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template