如果需要将一个数组输出一个简单的table可以采用以下代码(该数组非空)
<?php
$thead=array("name"=>"名称","tel"=>"电话");
$tbody=array(
array("name"=>"user1","tel"=>"123456"),
array("name"=>"user2","tel"=>"123456"),
array("name"=>"user3","tel"=>"123456"),
);
function echo_table($thead,$tbody)
{
$table_html="<table>%s</table>";
$tbody_html="";
$thead_html="<tr><th>".implode("</th><th>",$thead)."</th></tr>";
foreach ($tbody as $v)
{
$tbody_html.="<tr><td>".implode("</td><td>",$v)."</td></tr>";
}
$table_html=sprintf($table_html,$thead_html.$tbody_html);
return $table_html;
}
echo echo_table($thead,$tbody);
?>
输出效果: