Created
February 11, 2016 08:39
-
-
Save Maikuolan/12ec987b6237f7692147 to your computer and use it in GitHub Desktop.
Differences in how array_merge and how "+" handles conflicting indexes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr1 = array( | |
'a' => 'Hello', | |
'b' => 'World', | |
'c' => 'Foo', | |
'd' => 'Bar' | |
); | |
$arr2 = array( | |
'a' => 'Fello', | |
'b' => 'Borld', | |
'c' => 'Hoo', | |
'd' => 'War' | |
); | |
$arr3 = array( | |
0 => 1, | |
1 => 2, | |
2 => 3, | |
3 => 4 | |
); | |
$arr4 = array( | |
0 => 5, | |
1 => 6, | |
2 => 7, | |
3 => 8 | |
); | |
echo "1: "; | |
var_dump(array_merge($arr1, $arr2, $arr3, $arr4)); | |
echo "\n\n"; | |
echo "2: "; | |
var_dump($arr1 + $arr2 + $arr3 + $arr4); | |
echo "\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment