Detailed explanation of PHP function array_merge function_PHP tutorial

WBOY
Release: 2016-07-13 17:41:07
Original
1104 people have browsed it

There are two situations for merging arrays in PHP
1. If the two arrays have the same string key name:
$book1 = array(linux=>linux server configuration and Management,php=>PHP programming);
$book2 = array(linux=>Server configuration and management,jsp=>PHP);
$result = array_merge($book1,$book2);
print_r($result);
?>
The output is:
Array ( [linux] => Server Configuration and Management [php] => PHP Programming [jsp] => ; PHP )

indicates that the latter will replace the former. But if array_merge_recursive() is used, it can be retained and exist as a subarray. For example:
$book1 = array(linux=>linux server configuration and management,php=>PHP programming);
$book2 = array(linux=>server configuration With management, jsp=>PHP);
$result = array_merge_recursive($book1,$book2);
print_r($result);
?>
The output is:
Array ( [linux] => Array ( [0] => linux server configuration and management [1] => server configuration and management) [php] => PHP programming [jsp] => PHP )

2. If the two arrays have the same numerical key name:
$book1 = array (linux server configuration and management, PHP programming);
$book2 = array(Server Configuration and Management, PHP);
$result = array_merge($book1,$book2);
print_r($result);
?>
The result is:
Array ([0] => linux server configuration and management[1] => PHP programming[2] => Server configuration and management[3] => PHP)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486146.htmlTechArticleThere are two situations when merging arrays in PHP 1. If the two arrays have the same string key name: ?php $book1 = array(linux=linux server configuration and management,php=PHP programming); $book2...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!