There's a tonne of different approaches to this, so why not have some fun with it.
If you MUST use a for loop
No idea why you would, unless it's for a school assignment:
for($i=0;$i<count($data);$i++) {
echo('<tr>');
echo('<td>' . $data[$i][0] . '</td>');
echo('<td>' . $data[$i][1] . '</td>');
echo('<td>' . $data[$i][2] . '</td>');
echo('</tr>');
}
But then that's kinda stupid directly accessing the ID's, lets use another for loop in the row:
for($i=0;$i<count($data);$i++) {
echo('<tr>');
for($j=0;$j<count($data[$i]);$j++) {
echo('<td>' . $data[$i][$j] . '</td>');
}
echo('</tr>');
}
Replace it with an equally as boring foreach loop:
<table>
<?php foreach($items as $row) {
echo('<tr>');
foreach($row as $cell) {
echo('<td>' . $cell . '</td>');
}
echo('</tr>');
} ?>
</table>
Why not implode the array:
<table>
<?php foreach($items as $row) {
echo('<tr>');
echo('<td>');
echo(implode('</td><td>', $row);
echo('</td>');
echo('</tr>');
} ?>
</table>
Mix it up, screw the foreach, and go for a walk; and implode stuff along the way:
<?php
function print_row(&$item) {
echo('<tr>');
echo('<td>');
echo(implode('</td><td>', $item);
echo('</td>');
echo('</tr>');
}
?>
<table>
<?php array_walk($data, 'print_row');?>
</table>
Double walking... OMG
Yeah, it looks a little silly now, but when you grow the table and things get more complex, things are a little better broken out and modularized:
<?php
function print_row(&$item) {
echo('<tr>');
array_walk($item, 'print_cell');
echo('</tr>');
}
function print_cell(&$item) {
echo('<td>');
echo($item);
echo('</td>');
}
?>
<table>
<?php array_walk($data, 'print_row');?>
</table>