: This article describes how to merge arrays in PHP. For more information about PHP tutorials, see. 1. +
When the key names of two arrays are numeric or string keys, you can directly use "+", $ c = $ a + $ B, append the key name and value after $ a (the key name that $ B does not exist in $.
Features:
Does not overwrite, but append a key that does not exist and the corresponding value
Key names are not re-indexed
No matter whether it is all numeric keys or mixed keys, only append keys and values. if the key names are the same, no append is performed. that is, the first value is returned as the final result.
2. array array_merge (array arra1 [, array array2 [, array...])
Array_merge () combines the units of one or more arrays. the values in an array are appended to the previous array and used as the array of the returned results.
If the input array contains the same string key name, the value after the key name overwrites the previous value.
However, if the array contains a number key name, the subsequent values will not overwrite the original values, but will be appended to the back.
If only an array is assigned and the array is indexed by number, the key name is re-indexed continuously.
Features:
Number index, not covered. after the value is merged, the key name will be re-indexed continuously
String key name, the value after the key will overwrite the previous value
3. array array_merge_recursiv (array array1 [, array...])
Array_merge_recursive () combines the units of one or more arrays. the values in an array are appended to the back of the previous array and returned as the result array.
If the input array has the same string key name, these values will be merged into an array and recursive. Therefore, if a value is an array, this function combines the response entries into another array.
However, if the array has the same array key name, the next value will not overwrite the original value, but will be appended
Features:
The rule is basically the same as that of array_mege. it only uses recursive append when processing the same string key name.
The above describes how to merge arrays in PHP, including some content. I hope my friends who are interested in PHP tutorials can help me.