Parse the differences between array_merge and array + array in php. Array_merge discards the key of the original number, retains the key in the string form, and then forms a new array. no matter whether the key name is the same or not, it is not merged, unless the key name and value are the same, the array_merge discards the key of the original number, and retains the key in the string format, and then forms a new array, no matter whether the key name is the same or not, it is not merged, unless the key name and value are the same and must also be a string type key, the key is merged. Array + array is no matter what the situation is, it will only put the data in the previous array first into the newly generated array, then let's see if the second array has more numbers than the first array. if there are more, we will add it. it only counts, but in this case it will be added in: $ a = array ('D' => 'aass ', 'E' => 'adsdfs', 'asd' => 'asdsdd ', 'ddfg' => 'dssdf ');
The code is as follows:
$ B = array ('D' => 'adddd', 'adsdfs', 'asdfsdddd', 'D' => 'aass ');
$ D = $ a + $ B;
$ E = array_merge ($ a, $ B );
Var_dump ($ d );
Var_dump ($ e );
Print:
Array
'D' => string 'aass '(length = 4)
'E' => string 'adsdfs' (length = 6)
'Asd '=> string 'asdsdd' (length = 6)
'Ddfg' => string 'dssdf '(length = 5)
0 => string 'adsdfs' (length = 6)
1 => string 'asdfsddddd' (length = 10)
Array
'D' => string 'aass '(length = 4)
'E' => string 'adsdfs' (length = 6)
'Asd '=> string 'asdsdd' (length = 6)
'Ddfg' => string 'dssdf '(length = 5)
0 => string 'adsdfs' (length = 6)
1 => string 'asdfsddddd' (length = 10)
...