: This article mainly introduces the differences between PHP array addition and array_merge. if you are interested in PHP Tutorial, please refer to it. PHP array processing has powerful functions that result in various data processing functions.
The array addition and array_merge let the author step on a small pitfall.
1. see demo1:
public function action_test54(){ $a = array( '0'=>1567, '1'=>1568, '2'=>1569, '3'=>1570, ); $b = array( '1'=>1571, '2'=>1572, '3'=>1573, '4'=>1574 ); d($a + $b); dd(array_merge($a,$b)); }
Demo1 output:
array(5) ( 0 => integer 1567 1 => integer 1568 2 => integer 1569 3 => integer 1570 4 => integer 1574)
array(8) ( 0 => integer 1567 1 => integer 1568 2 => integer 1569 3 => integer 1570 4 => integer 1571 5 => integer 1572 6 => integer 1573 7 => integer 1574)
Conclusion:
$ A + $ B incremental coverage
Array_merge ($ a, $ B) merge
II. Demo2
public function action_test54(){ $a = array( 'a'=>1567, 'b'=>1568, 'c'=>1569, 'd'=>1570, ); $b = array( 'b'=>1571, 'c'=>1572, 'd'=>1573, 'e'=>1574 ); d($a + $b); dd(array_merge($a,$b)); }
Demo2 output:
array(5) ( "a" => integer 1567 "b" => integer 1568 "c" => integer 1569 "d" => integer 1570 "e" => integer 1574)
array(5) ( "a" => integer 1567 "b" => integer 1571 "c" => integer 1572 "d" => integer 1573 "e" => integer 1574)
Conclusion:
$ A + $ B incremental coverage
Array_merger ($ a, $ B) $ B is replaced with $ a first.
The above introduces the differences between PHP array addition and array_merge, including the content, hope to be helpful to friends who are interested in PHP tutorials.