3v4l.org

run code in 300+ PHP versions simultaneously
<?php $total = 7; $array = [1, 2]; // Dynamic, will be what you get from db. $array += array_fill(count($array), $total - count($array), 'empty'); var_dump($array);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(7) { [0]=> int(1) [1]=> int(2) [2]=> string(5) "empty" [3]=> string(5) "empty" [4]=> string(5) "empty" [5]=> string(5) "empty" [6]=> string(5) "empty" }

preferences:
184.4 ms | 403 KiB | 183 Q