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');
echo('| ' . $data[$i][0] . ' | ');
echo('' . $data[$i][1] . ' | ');
echo('' . $data[$i][2] . ' | ');
echo('');
}
But then that's kinda stupid directly accessing the ID's, lets use another for loop in the row:
for($i=0;$i');
for($j=0;$j' . $data[$i][$j] . '');
}
echo('');
}
Replace it with an equally as boring foreach loop:
');
foreach($row as $cell) {
echo('| ' . $cell . ' | ');
}
echo('');
} ?>
Why not implode the array:
');
echo('| ');
echo(implode(' | ', $row);
echo(' | ');
echo('');
} ?>
Mix it up, screw the foreach, and go for a walk; and implode stuff along the way:
');
echo('| ');
echo(implode(' | ', $item);
echo(' | ');
echo('');
}
?>
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:
');
array_walk($item, 'print_cell');
echo('');
}
function print_cell(&$item) {
echo('| ');
echo($item);
echo(' | ');
}
?>