3v4l.org

run code in 300+ PHP versions simultaneously
<?php $def = array( 1 => 'on', 2 => 'on', 3 => 'on' ); $fill = array( 2 => 'off' ); $res = array_merge($fill, $def); $res2 = array_merge($def, $fill); print_r($res); print_r($res2); function array_merge_custom($first, $second) { $result = array(); foreach($first as $key => $value) { $result[$key] = $value; } foreach($second as $key => $value) { $result[$key] = $value; } return $result; } $res3 = array_merge_custom($def, $fill); print_r($res3);

preferences:
36.8 ms | 402 KiB | 5 Q