Reputation: 13
I have an array of n
elements, of the form:
array (
array ("FOO", "BAR"),
array ("FOO", "BAR"),
array ("FOO", "BAR")...
)
I would like to loop over the array and display them on an HTML table.
Upvotes: 1
Views: 4379
Reputation: 26291
<? $bigArray = array( array("foo", "bar"), array("foo", "bar"), array("foo", "bar") ); ?>
<table>
<? foreach($bigArray as $a) { ?>
<tr><? for($j=0; $j <= 5; ++$j) { ?><td><?= $a[$j] ?></td><? } ?></tr>
<? } ?>
</table>
The advantage of this approach is that you can prototype with your favorite html editor and plug the commands in. Note that this only works when your server supports short_tags.
Upvotes: 1
Reputation: 158
Try a foreach loop.
Foreach:
<?
$bigArray = array( array("foo", "bar"), array("foo", "bar"), array("foo", "bar") );
?>
<table>
<?
foreach($bigArray as $a)
{
echo "<tr><td>".$a[0]."</td><td>".$a[1]."</td></tr>";
}
?>
</table>
Upvotes: 1