开发者

php looping array - html table

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 ta开发者_Go百科ble.


<? $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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜