3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $levels = [1=>10, 2=>20, 3=>30, 6=>60]; $a = array_keys($levels); sort($a); $max = end($a); $toAdd = array_diff(array_keys(array_fill(1, $max, 0)), $a); $result = array_fill_keys($toAdd, 0); $merged = array_merge($levels, $result); var_dump($result); var_dump($merged);
based on kHOV0
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0rc3
array(2) { [4]=> int(0) [5]=> int(0) } array(6) { [0]=> int(10) [1]=> int(20) [2]=> int(30) [3]=> int(60) [4]=> int(0) [5]=> int(0) }