Forum Moderators: coopster
<?php
header("content-type:text/html");
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<style type="text/css">
body { font-family:arial,helvetica,sans-serif; }
p,table { text-align: center; }
table { width: 400px; margin: auto; }
.wht { background: #fff; }
.gray { background: #eaeaea; }
</style>
</head>
<body>
<p>Output columns.</p>
';
// I make them odd for a reason, watch.
//
$list_array = array (1,2,3,4,5,6,7,8,9,10,11);
$assoc_array = array (
1 => 'One',
2 => 'Two',
3 => 'Three',
4 => 'Four',
5 => 'Five',
6 => 'Six',
7 => 'Seven',
8 => 'Eight',
9 => 'Nine',
10 => 'Ten',
11 => 'Eleven'
);
$bg=null;
$colcount=0;
//
echo '<table border=1">';
foreach ($list_array as $scalar) {
if ($colcount==0) {
echo "<tr>";
$bg = ($bg=='wht')?'gray':'wht';
}
echo "<td class=\"$bg\">$scalar</td>";
$colcount++;
if ($colcount >= 2) { echo "</tr>\n"; $colcount = 0; }
}
//
if ($colcount==1) { echo "<td> </td></tr>\n"; }
echo '</table><p> </p><table border="1">';
//
$colcount=0;
foreach ($assoc_array as $key => $value) {
if ($colcount==0) {
echo "<tr>";
$bg = ($bg=='wht')?'gray':'wht';
}
echo "<td class=\"$bg\">$key</td><td class=\"$bg\">$value</td>";
$colcount++;
if ($colcount >= 2) { echo "</tr>\n"; $colcount = 0; }
}
//
if ($colcount==1) { echo "<td> </td><td> </td></tr>\n"; }
echo '</table>';
?>