3v4l.org

run code in 300+ PHP versions simultaneously
<?php $max = 100; // The last number $cols = 5; // The point at which a new line will start $arr = array_chunk(range(1, $max), $cols); // Magic ;D // Print the data. foreach ($arr as $key => $row) { // This will reverse every other row $row = ($key % 2 === 0) ? $row : array_reverse($row); foreach ($row as $value) { $value = str_pad($value, strlen($max), ' ', STR_PAD_LEFT); echo "{$value} "; } echo "\n"; }
Output for 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
1 2 3 4 5 10 9 8 7 6 11 12 13 14 15 20 19 18 17 16 21 22 23 24 25 30 29 28 27 26 31 32 33 34 35 40 39 38 37 36 41 42 43 44 45 50 49 48 47 46 51 52 53 54 55 60 59 58 57 56 61 62 63 64 65 70 69 68 67 66 71 72 73 74 75 80 79 78 77 76 81 82 83 84 85 90 89 88 87 86 91 92 93 94 95 100 99 98 97 96

preferences:
99.48 ms | 408 KiB | 5 Q