PHP输出数组作为HTML表 [英] PHP output array as an HTML table

查看:95
本文介绍了PHP输出数组作为HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数组输出为html表,该数组的示例为..

I am trying to output an array as an html table, a sample of the array is..

Array
(
    [18] => Array
        (
            [colour] => red
            [size] => large
            [age] => 220
        )
        [19] => Array
        (
            [colour] => yellow
            [size] => small
            [age] => 20
        )
        [12] => Array
        (
            [colour] => brown
            [size] => large
            [age] => 2
        )
)

I可以为一个简单的数组做一个foreach,但是没有人有示例显示将其转换为这种类型的数组的表吗?

I am ok with doing a foreach for a simple array but does anyone have an example showing this being converted into a table for this type of array?

推荐答案

尝试类似这样的事情:

$data = //your array
$html = "<table>";
foreach($data as $row) {
    $html .= "<tr>";
    foreach ($row as $cell) {
        $html .= "<td>" . $cell . "</td>";
    }
    $html .= "</tr>";
}
$html .= "</table>";

您的问题非常模糊,所以这是一个模糊的答案,但是您应该得到大致的主意:P

Your question is extremenly vague so this is a vague answer, but you should get the general idea :P

这篇关于PHP输出数组作为HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆