i typically don't just give the code to people... but this may be a bit difficult to explain or at least explain well enough for you to understand, so here is some code that has been posted on the board before, disect it and make sure you understand how it works, then implement it
<?php
function vertHorizLoop($array, $cols=3, $horiz=true, $table=true)
{
$output = '';
$count = count($array);
if($table)
$output .= '
<table border="0" cellpadding="0" cellspacing="0" width="500">
<tr>';
if(!$horiz)
{
$sect = array();
for($i=0; $i<$cols; $i++)
$sect[$i] = array();
$max = ceil($count/$cols);
$k=0;
for($i=0; $i<$count; $i++)
{
if($i%$max==0 && $i!=0)
$k++;
$sect[$k][] = $array[$i];
}
}
if($horiz)
{
for($i=0; $i<count($array); $i++)
{
if($i%$cols==0)
{
if($table)
$output .= '
</tr>
<tr>';
else
$output .= '<br>';
}
if($table)
$output .= '
<td>'.$array[$i].'</td>';
else
$output .= $array[$i].' ';
}
}
else
{
for($i=0; $i<$max; $i++)
{
foreach($sect as $key=>$arr)
{
if($table)
$output .= '
<td>'.$arr[$i].'</td>';
else
$output .= $arr[$i].' ';
}
if($table)
$output .= '
</tr>
<tr>';
else
$output .= '<br>';
}
}
if($table)
$output .= '
</tr>
</table>';
echo $output;
}
$block = array('Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot', 'Golf', 'Hotel', 'India', 'Juliet', 'Kilo', 'Lima', 'Mike', 'November', 'Oscar', 'Papa', 'Quebec', 'Romeo', 'Sierra', 'Tango', 'Uniform', 'Victor', 'Whiskey', 'Xray', 'Yankee', 'Zulu');
echo '<h3>Horizontal [<i>Table</i>]:</h3>';
vertHorizLoop($block, 5, true);
echo '<hr>
<h3>Vertical [<i>Table</i>]:</h3>';
vertHorizLoop($block, 5, false);
echo '<hr>
<h3>Horizontal [<i>HTML</i>]:</h3>';
vertHorizLoop($block, 5, true, false);
echo '<hr>
<h3>Vertical [<i>HTML</i>]:</h3>';
vertHorizLoop($block, 5, false, false);
?>