Home > php教程 > php手册 > PHP中通过加号合并数组的一个简单方法分享

PHP中通过加号合并数组的一个简单方法分享

WBOY
Release: 2016-06-13 12:12:06
Original
1009 people have browsed it

代码:

复制代码 代码如下:


$a = array('a' => 'a', 'b' => 'b');
$b = array('c' => 'c', 'd' => 'd');
$c = $a + $b;
print('

'); <br>print_r($c); <br>print('
Copy after login
');
?>

结果:

复制代码 代码如下:


Array
(
[a] => a
[b] => b
[c] => c
[d] => d
)


注意:加号和array_merge()函数还是有区别的,就是当用加号合并数组时,如果数组间存在同名的键,那么保留前面数组对应的键值,而array_merge()函数正好相反。
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