The first choice is to explain that this article is somewhat suspected of a title party. I have previously written an article to compare the three methods for php to merge one-dimensional arrays, later, I used these three methods to process multi-dimensional arrays. The strange thing is that neither array_merge nor ++ reported an error. I thought they could also be used to process multi-dimensional arrays. After carefully observing the results, we found that the two methods are actually
The first choice is to explain that this article is somewhat suspected of a title party. I have previously written an article to compare the three methods for php to merge one-dimensional arrays, later, I used these three methods to process multi-dimensional arrays. The strange thing is that neither array_merge nor ++ reported an error. I thought they could also be used to process multi-dimensional arrays. After carefully observing the results, we found that the two methods are actually
The first choice is to explain that this article is somewhat suspected of a title party. I have previously written an article to compare the three methods for php to merge one-dimensional arrays, later, I used these three methods to process multi-dimensional arrays. The strange thing is that neither array_merge nor ++ reported an error. I thought they could also be used to process multi-dimensional arrays. After carefully observing the results, we found that the two methods were actually soy sauce.
Please refer to the code
$array1 = array(2,4,"color" => "red"); $array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4); $array3 = array("e","f","red"=>array("little"=>"little",3,5),2,4); $array4 = array("a","b","red"=>array("little"=>"big",4,6),8,9); echo "----------------array_merge---------------".PHP_EOL; print_r(array_merge($array3,$array4)); echo "----------------+++++++++++++++++++++---------------".PHP_EOL; print_r($array3+$array4); echo "----------------array_merge_recursive---------------".PHP_EOL; print_r(array_merge_recursive($array3,$array4));
The result is as follows:
----------------array_merge---------------Array( [0] => e [1] => f [red] => Array ( [little] => big [0] => 4 [1] => 6 ) [2] => 2 [3] => 4 [4] => a [5] => b [6] => 8 [7] => 9)----------------+++++++++++++++++++++---------------Array( [0] => e [1] => f [red] => Array ( [little] => little [0] => 3 [1] => 5 ) [2] => 2 [3] => 4)----------------array_merge_recursive---------------Array( [0] => e [1] => f [red] => Array ( [little] => Array ( [0] => little [1] => big ) [0] => 3 [1] => 5 [2] => 4 [3] => 6 ) [2] => 2 [3] => 4 [4] => a [5] => b [6] => 8 [7] => 9)
After reading the code, I think you can see the meaning of soy sauce: array_merge and + treat the values of the First-dimensional array as a simple variable, then, the imported prime group is processed again by processing the one-dimensional prime group.
Only array_merge_recursive uses an iterative method to process the prime groups in each dimension.
Original article address: php multi-digit combination, thanks to the original author for sharing.