Two ways to merge arrays: $a + $b, array_merge ($a, $b)
Merging indexed arrays using the operator +, duplicate indexes are discarded, and duplicate indexes with Array_merge () are reset, as in the following scenario:
1php > $a =Array (); 2 3php > $b = Array (1='Data'); 4 5php > $c = $a +$b; 6 7php > $d =array_merge ($a, $b); 8 9php >var_dump ($c, $d); Ten One //Output Results A -Array1) { [1] =string(4)"Data" } - theArray1) { [0] =string(4)"Data"}
Therefore, when using + to merge two indexed arrays, the values may be discarded, and array_merge will not, resetting the duplicate index:
1php > $a = Array (1=' One',2=' Both',3='three'); 2php > $b = Array (3='three',4=' Four',5='Five'); 3php > $c = $a +$b; 4php > $d =array_merge ($a, $b); 5php >var_dump ($c, $d); 6Array5) { 7[1] =string(3)" One" 8[2] =string(3)" Both" 9[3] =string(5)"three" Ten[4] =string(4)" Four" One[5] =string(4)"Five" A } - -Array6) { the[0] =string(3)" One" -[1] =string(3)" Both" -[2] =string(5)"three" -[3] =string(5)"three" +[4] =string(4)" Four" -[5] =string(4)"Five" +}
Similarities and differences between the two ways of merging two arrays