PHP uses the array_merge() function to merge two arrays, array_merge array_PHP tutorial

WBOY
Release: 2016-07-13 10:02:57
Original
893 people have browsed it

How PHP merges two arrays through the array_merge() function, array_merge array

The example in this article describes how PHP merges two arrays through the array_merge() function. Share it with everyone for your reference. The specific analysis is as follows:

php merges two arrays through the array_merge() function. array_merge() is a php function that is used to merge two or more arrays. The latter array will be appended to the previous array and the result array will be returned. It accepts two or more arrays and returns an array containing all elements.

$first = array("aa", "bb", "cc");
$second = array(11,22,33);
$third = array_merge($first, $second);
 
foreach ( $third as $val ) {
 print "$val<br />";
}
Copy after login

The execution result of the above code is as follows:

The output is an array with ('aa', 'bb', 'cc', 11, 22, 33)
Copy after login

Special tip: If the input array has the same string key, then the subsequent value of that key will overwrite the previous one. However, if the array contains numeric keys, subsequent values ​​will not overwrite the original values, but will be appended.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969484.htmlTechArticlephp method of merging two arrays through the array_merge() function, array_merge array This article describes the example of php through array_merge() Function method to merge two arrays. Share it with everyone for your reference...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template