We first give two Arrays
Copy codeThe Code is as follows: <? Php
$ R = array (1, 2, 3, 4, 5, 6 );
$ E = array (7,8, 9, 10 );
?>
Here we use the array_merge and the plus sign to add these two arrays.Copy codeThe Code is as follows: <? Php
Print_r ($ r + e); // output <span style = "font-family: Simsun; font-size: 16px; "> Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6) </span>
Print "<br/> ";
Print_r (array_merge ($ r, $ e); // output <span style = "font-family: Simsun; font-size: 16px; "> Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9) </span>
?>
It can be seen from this that the value in an array is combined with array_merge and appended to the value behind the previous array. If the array contains the number key name, the subsequent values will not overwrite the original values, but will be appended to the back. However, the plus sign is used to merge arrays. If the key name is the same, the first array value is used.
Next we will change the array given aboveCopy codeThe Code is as follows: <? Php
$ R = array ('R' => 1, 2, 3, 4, 5, 6 );
$ E = array (<span style = "background-color: rgb (245,250,255);"> 'R' => </span> );
?>
Copy codeThe Code is as follows: <? Php
Print_r ($ r + e ); // output Array ([r] => 1 [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6)
Print "<br/> ";
Print_r (array_merge ($ r, $ e )); // output Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9)
?>
It can be seen from this that the value in an array is combined with array_merge and appended to the value behind the previous array. If the names of non-numeric keys are the same, the values of the subsequent arrays overwrite the values of the preceding arrays. However, the plus sign is used to merge arrays. If the key name is the same, the first array value is used.