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 />"; }
The execution result of the above code is as follows:
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.