Last active
December 13, 2015 22:39
-
-
Save michaeluno/4985656 to your computer and use it in GitHub Desktop.
array_merge() is useful to merge arrays but it is confusing which parameter takes precedence. Also it is different from the method with the plus operator. ( e.g. $arr1 + $arr2 ). It could be more like join two array elements. So it may be used to append or pre-pend numerically indexed arrays.
This file contains 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 | |
$array1 = array( 'a', 'b', 'c' ); | |
$array2 = array( 'd', 'e', ); | |
$result1 = array_merge( $array2, $array1 ); | |
$result2 = array_merge( $array1, $array2 ); | |
echo '<pre>' . print_r( $result1, true ) . '</pre>'; | |
echo '<pre>' . print_r( $result2, true ) . '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment