Here’s one that accepts a variable number of rows and columns:
<?php
$rows = 9;
$cols = 9;
for ($row = 0; $row < $rows; $row++) {
$num = ($row % $cols);
for ($col = 0; $col < $cols; $col++) {
if (++$num == $cols + 1) {
$num = 1;
}
echo $num . ' ';
}
echo PHP_EOL;
}
solved How to create number list 1 until 9 and plus 1 at another row in php?