这里我有一个存储有关某些状态的信息的多维数组。所有的信息都显示出来,但我把它格式化成4x11的表格很麻烦。
<?php
$stateinfo = array
(
array("Alabama","Montgomery","4,779,736",23),
array("Alaska", "Juneau", "710,231", 47),
array("Arizona","Phoenix","6,329,017", 18),
array("Arkansas","Little Rock", "2,915,918", 32),
array("California","Sacramento","37,253,956",1),
array("Colorado","Denver","5,029,196",22),
array("Connecticut","Hartford","3,518,288",29),
array("Delaware","Dover","897,934",45),
array("Florida","Tallahassee","18,801,310",4),
array("Georgia","Atlanta","9,687,653",9),
array("Hawaii","Honolulu","1,360,301",42)
);
for($row = 0; $row <count($stateinfo);$row++)
{
for($col=0;$col <count($stateinfo[$row]);$col++)
{
echo $stateinfo[$row][$col];
}
echo "<br>";
}
?>
当前输出:
需要输出:
答案 0 :(得分:-1)
我会这样做:
<table>
<?php
foreach($stateinfo as $row) {
echo '<tr><td>'.implode('</td><td>', $row).'</td></tr>';
}
?>
</table>
然后将样式应用于表/ td以获得特定的间距。
答案 1 :(得分:-2)
好像你只想要一些格式化?然后,当您循环打印多维数组时,只需在每个元素或
之间添加一些padding:5px;
即可。实际上有一百万种方法可以做到这一点: