-
-
/** - desc: array merge
- link: bbs.it-home.org
- date: 2013/2/22
- */
- $a = array( 'a' => 1, 'b' => 2 );
- $b = array( 'b' => 3, 'd' => 4 );
//Array merge
- $array_merge = array_merge( $a, $b );
- echo '< ;pre>';
- print_r( $array_merge );
//Array recursive merge
- $array_merge_recursive = array_merge_recursive( $a, $b );
- print_r( $array_merge_recursive );
- echo ' ';
- ?>
-
Copy the code
output result:
Array
(
[a] => 1
=> 3
[d] => 4
)
Array
(
[a] => 1
=> Array
(
[0] => 2
[1] => 3
)
[d] => 4
)
We can see:
When array_merge encounters the same value, the second array key overwrites the first array key, while the array_merge_recursive function uses subscript merging for arrays of the same value.
|