3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $number = 28; $columnCount = 4; for($i = 1, $loopCounter = 1; $i <= $number; $i = $i + $columnCount, $loopCounter++) { $range = range($i, $i+$columnCount - 1); if($loopCounter % 2 === 0) { $range = array_reverse($range); } foreach($range as $n) { echo str_pad($n, 2, ' ', STR_PAD_LEFT) . " "; } echo "\n"; }
Output for 4.3.0 - 5.6.38, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.3.2
1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13 17 18 19 20 24 23 22 21 25 26 27 28