Home  >  Article  >  Backend Development  >  PHP method to merge two arrays through array_merge() function_PHP tutorial

PHP method to merge two arrays through array_merge() function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:29898browse

How to merge two arrays in php through the array_merge() function

This article mainly introduces the method of merging two arrays in php through the array_merge() function. An example analysis of php Friends who need tips on how to use the array_merge() function to merge arrays can refer to it

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.

?

1

2

3

4

5

6

7

$first = array("aa", "bb", "cc");

$second = array(11,22,33);

$third = array_merge($first, $second);

 

foreach ( $third as $val ) {

print "$val
";

}

1 2

3

4

5

6

1

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

7

$first = array("aa", "bb", "cc");

$second = array(11,22,33);

$third = array_merge($first, $second);

foreach ( $third as $val ) {print "$val
"; }
The execution result of the above code is as follows:
?
1 The output is an array with ('aa', 'bb', 'cc', 11, 22, 33)
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. http://www.bkjia.com/PHPjc/969962.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969962.htmlTechArticlephp method of merging two arrays through the array_merge() function. This article mainly introduces php through the array_merge() function. How to merge two arrays, an example analysis of the array_merge() function in 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