search
Homephp教程php手册PHP函数array_merge函数详解

PHP函数array_merge函数详解

Jun 13, 2016 am 10:39 AM
arraymergephpfunctionmergeConditionarrayofDetailed explanation

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 )

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.