I have an array which I would like to dump into a table, but have a new column X number of items. For example:
item 1 | item 2 | item 3 | item 4 |
item 5 | item 6 | item 7 | item 8 |
item 9 | and so on...
I can already make it add a new column after a certain number of items (in this case, 4) with this code:
$input = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten');
$cols = 4;
echo "<table border=\"5\" cellpadding=\"10\">";
for ($i=0; $i < count($input); $i++)
{
echo "<tr>";
for ($c=0; $c<$cols; $c++)
{
$n = $i+$c;
echo "<td>$input[$n]</td>";
}
echo "</tr>";
$i += $c;
}
echo "</table>";
But for some reason, after one column ends with 'four', the next starts with 'six'.
$iwithin the loop, and then thefor()itself will do$i++. Yuu should do eitherfor($i...; $i += $c)at the top or$i += $c - 1;at the bottom