First look at the key name is string, the difference between the two:
Copy Code code as follows:
<?php
$arr 1 = Array (' A ' => ' PHP ');
$arr 2 = Array (' A ' => ' JAVA ');
If the key name is a character and the key name is the same, the array element value after Array_merge () overrides the preceding array element value
Print_r (Array_merge ($arr 1, $arr 2)); Array ([a] => JAVA)
If the key name is a character and the key name is the same, the addition of the array will result in the first occurrence of the value
Print_r ($arr 1+ $arr 2); Array ([a] => PHP)
?>
If the key name is a number, the difference is:
Copy Code code as follows:
<?php
$arr 1 = Array ("C", "PHP");
$arr 2 = Array ("JAVA", "PHP");
If the key name is a number, array_merge () does not overwrite
Print_r (Array_merge ($arr 1, $arr 2))//array ([0] => C [1] => PHP [2] => JAVA [3] => PHP)
If the key name is an array, the sum of the arrays will result in the first occurrence of the value, and the same will be discarded after the same key name
Print_r ($arr 1+ $arr 2);//array ([0] => C [1] => PHP)
?>
Special attention should be paid to. On the "difference between the sum of array_merge and Arrays", it is clear that back to my original question "How do I get the most efficient collection of two array values of the same value for the word keys?", not this is going to iterate over each array, PHP also has a function to get you not used: Array_ Merge_recursive-recursively merges one or more arrays, and if the input array has the same string key name, the values are merged into an array. The following example:
Copy Code code as follows:
<?php
$arr 1 = Array ("A" => "PHP", "C");
$arr 2 = Array ("A" => "Java", "C", "Ruby");
Print_r (Array_merge_recursive ($arr 1, $arr 2));
?>
The results are as follows:
Array
(
[A] => Array
(
[0] => PHP
[1] => Java
)
[0] => C
[1] => C
[2] => Ruby
)
This allows you to get a collection of element values that have the same key names in multiple arrays.