I've got a function like that, wrote it a few years back when I was still learning php, so it's probably not as optimised as it could be.
It does allow you to set the number of columns you want and distributes the items accordingly (adding empty cells if the final row isn't long enough)
It was originally designed for displaying a table of links, hence the m_items variable is a hash of url=name&...
PHP Code:
function TableMatrix($m_width, $m_border, $m_cols, $m_items) {
$m_done = "false";
$m_newcol = "false";
echo"<table align=center width=$m_width border=$m_border>\n";
$m_split = explode("&", $m_items);
$colcount = 1;
$itemcount = 0;
$m_totitem = count ($m_split);
while ($m_done == "false") {
if ($itemcount < $m_totitem) {
$temp = $m_split[$itemcount];
$m_urlname = explode("=", $temp);
if (($colcount == 1) && ($colcount != $m_cols)) {
echo"<tr>\n<td width=33%><a href='$m_urlname[0]' target='_blank'>$m_urlname[1]</a></td>\n";
$colcount++;
$m_newcol = "false";
}
elseif ($colcount < $m_cols) {
echo"<td width=33%><a href='$m_urlname[0]' target='_blank'>$m_urlname[1]</a></td>\n";
$colcount++;
$m_newcol = "false";
}
elseif ($colcount == $m_cols) {
echo"<td width=33%><a href='$m_urlname[0]' target='_blank'>$m_urlname[1]</a></td>\n</tr>\n";
$colcount = 1;
$m_newcol = "true";
}
$itemcount++;
}
elseif (($colcount <= $m_cols) && ($m_newcol == "false")) {
while ($colcount < $m_cols) {
echo"<td width=33%> </td>\n";
$colcount++;
}
if ($colcount = $m_cols) {
echo"<td width=33%> </td>\n</tr>\n";
$m_done = "true";
}
}
else { $m_done = "true"; }
}
echo"</table>";
}
hmm, just noticed on here, that the td widths should probably calculated from the number of cols, oh well.