This article mainly introduces the PHP through the Array_merge () function merges two arrays the method, the example analyzes the PHP array_merge () function merges the array the use skill, needs the friend to be possible to refer to under
This example describes how PHP merges two arrays through the Array_merge () function. Share to 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 merges two or more arrays, appends the array to the previous array, and returns an array of results. It takes two or more than two arrays and returns an array that contains all the 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 code above executes the following results:
?
| 1 |
The output is a array with (' AA ', ' BB ', ' cc ', 11, 22, 33) |
Special NOTE: If the input array has the same string key, then the value of the key then overwrites the previous one. However, if the array contains numeric keys, subsequent values will not overwrite the original value, but will be appended.
I hope this article will help you with your PHP program design.