You got the array:
$tab = [1, 2, 3, 4, 5, 6, 7, 8, 9];
I want to make table with values from array tab.
Table must be max 4-columns.
Its should look like this:
1 2 3 4
5 6 7 8
9
My example code (not working):
$tab = [1, 2, 3, 4, 5, 6, 7, 8, 9];
$max = count($tab);
// 1 FOR - ROWS
echo "<table>";
for ( $i = 0; $i < $max; $i+=4 )
{
echo "<tr>";
// 2 FOR - COLUMNS
for ( $x = $i; $x < 4; $x++ ) //our array is 9-elemented, in third row $x going to be out of index
{
printf('<td>%s</td>', $tab[$x]);
}
echo "</tr>";
}
echo "</table>";