Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

difference between array_merge and +

<?php
// Plus operator does overwrite matching keys.
$one = [ 'one', 'two', 'three' ];
$two = [ 'four', 'five', 'six' ];

print_r($one + $two);
/** Output:
 *  Array
 *  (
 *      [0] => one
 *      [1] => two
 *      [2] => three
 *  )
 */
print_r(array_merge($one, $two));
/** Output:
 *  Array
 *	(
 *    [0] => one
 *    [1] => two
 *    [2] => three
 *    [3] => four
 *    [4] => five
 *    [5] => six
 *	)
 */
Source by onlinephp.io #
 
PREVIOUS NEXT
Tagged: #difference
ADD COMMENT
Topic
Name
9+4 =