3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo "<pre>\n"; $n=4; $max_length = $n * 2 - 1; for ($i = 1; $i <= $n * 2 - 1; $i++) { $this_n = ($i <= $n) ? $i : $n * 2 - $i; $num_ns = $this_n * 2 - 1; echo str_repeat(' ', ($max_length - $num_ns) / 2); echo str_repeat("$this_n", $num_ns); echo "\n"; } echo '</pre>';

preferences:
24.71 ms | 404 KiB | 5 Q