Home > php教程 > php手册 > PHP函数array_merge函数详解

PHP函数array_merge函数详解

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:39:56
Original
1243 people have browsed it

PHP中合并数组分成两种情况
1、如果这两个数组中有相同的字符串键名:
$book1 = array(linux=>linux服务器配置与管理,php=>PHP程序设计);
$book2 = array(linux=>服务器配置与管理,jsp=>PHP);
$result = array_merge($book1,$book2);
print_r($result);
?>
输出为:
Array ( [linux] => 服务器配置与管理 [php] => PHP程序设计 [jsp] => PHP )

说明,后者将替换前者。但如果使用的是array_merge_recursive()则可保留,并作一个子数组存在。如:
$book1 = array(linux=>linux服务器配置与管理,php=>PHP程序设计);
$book2 = array(linux=>服务器配置与管理,jsp=>PHP);
$result = array_merge_recursive($book1,$book2);
print_r($result);
?>
输出为:
Array ( [linux] => Array ( [0] => linux服务器配置与管理 [1] => 服务器配置与管理 ) [php] => PHP程序设计 [jsp] => PHP )
 
2、如果这两个数组中有相同的数值键名:
$book1 = array(linux服务器配置与管理,PHP程序设计);
$book2 = array(服务器配置与管理,PHP);
$result = array_merge($book1,$book2);
print_r($result);
?>
结果是:
Array ( [0] => linux服务器配置与管理 [1] => PHP程序设计 [2] => 服务器配置与管理 [3] => PHP )

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template