3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [0 => 0, 1=> 0, 4 => 0, 6 => 0]; $full = array_fill(0,6,999); foreach($full as $k => &$v) if (isset($arr[$k])) $v = $arr[$k]; print_r($full); $new = $arr + array_fill(0,6,999); ksort($new); print_r($new);

preferences:
37.13 ms | 406 KiB | 5 Q