- ceil: documentation ( source)
- range: documentation ( source)
<?php
$result=range(1,8);
$left=count($result);
$colLeft=4;
$limit=16;
$i=0;
foreach($result as $row)
{
if($i==0)
{
$limit=ceil($left/$colLeft);
echo '<tr>';
}
echo '<td>'.$row.'</td><td>'.$row.'</td><td>'.$row.'</td>';
$i++;
$left--;
if($i>=$limit)
{
echo '</tr>';
$i=0;
$colLeft--;
}
}