> I'm sure this has been done before, but I was wondering if anyone could
> point me to a sample of code that shows how to display an array in a
> multi-column format like so:
>
> A F K
> B G L
> C H M
> D I N
> E J O
>
> instead of
>
> A B C D E
> F G H I J
> K L M N O
>
>
> Thanks,
> Jim
You could use an HTML table with three columns. The basic structure is:
<table>
<tr valign=top>
<td>first column</td>
<td>second column</td>
<td>third column</td>
</tr>
</table>
That said, the trick is to figure out how many elements are in your array and
then to decide how many columns to display.
$n = count($array);
$n3 = ceil($n/3); // or try floor()
print "<table><tr valign='top'><td>";
foreach($array as $element)
{
print $element;
print (++$row % $n3) ? "" : "</td><td>";
}
print "</td></tr></table>";
James
_____
James D. Keeline
http://www.Keeline.com http://www.Keeline.com/articles
http://Stratemeyer.org http://www.Keeline.com/TSCollection
http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
Summer Semester Begins Jun 20 -- New Classes Start Every Few Weeks.
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/