Php uses the array_merge () function to merge two arrays.
This article describes how to merge two Arrays Using the array_merge () function in php. The example shows how to use the array_merge () function in php to merge arrays. For more information, see
This example describes how php combines two arrays through the array_merge () function. Share it with you for your reference. The specific analysis is as follows:
Php uses the array_merge () function to merge two arrays. array_merge () is a php function used to combine two or more arrays. The last array is appended to the back of the previous array, and returns an array of results. 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 <br/> "; } |
The preceding code execution result is as follows:
?
1 |
The output is an array with ('A', 'bb ', 'cc', 11, 22, 33) |
Note: If the input array has the same string key, this key will overwrite the previous one. However, if the array contains a number key, the subsequent values will not overwrite the original values, but will be appended.
I hope this article will help you with php programming.