$count=0; function output($array,$index) { print "<table>"; foreach($array as $field) { if($count==0){print "<tr>";} print "<td>$field</td>"; if($count==$index){print "</tr>";$count=0;} } print "</table>"; }
If You need to display a certain number of columns in your output, just pass that number throught $index.