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