, ( )
<?php
$options = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
$numCols = 3;
$pad = false;
$rows = (int)ceil(count($options) / $numCols);
$c = count($options) % $numCols;
$col = 1;
for ($j = 0; $j < $numCols; $j++) {
for ($i = 0; $i < $rows; $i++) {
if (($col <= $c && $i == $rows - 1) || $i != $rows - 1 || $c == 0) {
$arr[$i][$j] = array_shift($options);
}
}
$col++;
}
if ($pad) {
$arr[count($arr) - 1] = array_pad($arr[count($arr) - 1], $numCols, null);
}
?>
<table border="1" colspan="0" cellspan="0">
<?php for ($i = 0; $i < count($arr); $i++) { ?>
<tr>
<?php for ($j = 0; $j < count($arr[$i]); $j++) { ?>
<td><?= $arr[$i][$j]; ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
, , . , .
, , . ($numCols
), . .
, , . :
$options
. , . .$numCols
, , . " " ; , , <td>
, HTML, .$pad
, , - $options
, , $numCols
.
, . , for , , .
, , . $pad
true, , .
, .
, , ; , , , , , .
. , - -, , exit, , , . , , , PHP. , ( , for ).
, !
