We first give two arrays
<?php
$r = array(1,2,3,4,5,6);
$e = array(7,8,9,10);
?>
Now let's use array_merge and plus sign to use these two arrays
<?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>
?>
From here, we can see that the values in an array are combined with array_merge attached to the previous array. Returns the resulting array If the array contains numeric key names, the following values will not overwrite the original value, but will be appended to the later one. However, if the key names are the same, the first array value will be taken, and the following will be ignored
Let's change the array given above
<?php
$r = array('r'=>1,2,3,4,5,6);
$e = array(<span style="background-color: rgb(245, 250, 255); ">'r'=></span>7,8,9,10);
?>
<?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 )
?>
From here, we can see that the values in an array are combined with array_merge attached to the previous array. If the non-numeric key names are the same, the value of the subsequent array will overwrite the value of the previous array. However, if the key names are the same, the first array value will be taken, and the following will be ignored
Copy the codeThe code is as follows:
<?php
$r = array(1,2,3,4,5,6);
$e = array(7,8,9,10);
?>
Now let's use array_merge and plus sign to use these two arrays
Copy the 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>
?>
From here, we can see that the values in an array are combined with array_merge attached to the previous array. Returns the resulting array If the array contains numeric key names, the following values will not overwrite the original value, but will be appended to the later one. However, if the key names are the same, the first array value will be taken, and the following will be ignored
Let's change the array given above
Copy the 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>7,8,9,10);
?>
Copy the 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 )
?>
From here, we can see that the values in an array are combined with array_merge attached to the previous array. If the non-numeric key names are the same, the value of the subsequent array will overwrite the value of the previous array. However, if the key names are the same, the first array value will be taken, and the following will be ignored