up vote 1 down vote favorite
share [fb]

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.

link|improve this question
feedback

4 Answers

up vote 1 down vote accepted
<? $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.

link|improve this answer
you can replace the 5 with your bound (i.e. $j < $max_elements) – Foo Bah Feb 9 at 4:39
feedback

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>
link|improve this answer
feedback

PHP loop might help. Tutorial.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.