3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $total = 7; $array = [1, 2]; // Dynamic, will be what you get from db. $sizeofarray = count($array); if ($sizeofarray < $total) { $difference = $total - $sizeofarray; for ($i = 1; $i <= $difference; $i++) { // Fill array with other values. $array[] = ''; } } foreach ($array as $item) { echo $item; }
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0beta1
12