从PHP数组中生成HTML表 [英] Generate HTML table from PHP array

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

问题描述

我在我的mySQL数据库中查询了以下PHP数组 $ array

I have the following PHP array queried from my mySQL Database in $array:

Print_r 带有预标签给我:

数组

[A] => 1
[B] => 2

Array ( [A] => 1 [B] => 2 )

这应该在HTML表格中很好地格式化。

This should be nicely formatted in a HTML table.


A 1
B 2

非常感谢任何帮助!

推荐答案

仅仅因为它很简单:

$array = array("A" => "1", "B" => "2");

echo "<table>";     
foreach( $array as $key => $value ){
    echo "<tr><td>" . $key . "</td><td>" . $value . "</td></tr>";
}
echo "</table>";

但是,在你问这里之前,你应该尝试一下,如果你有问题,你可以询问它。

But you should try before you ask here, then, if you have a problem, you can ask about it.

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

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