我刚刚用 php 数组填充了 html 表,但现在我看到有一些空单元格。建表的代码是:
echo "<table id='data' style='border: 1px solid black'><tbody>";
echo "<th>Country </th>";
echo "<th>Counter</th>";
foreach($analysis_data as $row){
echo "<tr>";
foreach(['country','counter'] as $attribute){
echo "<td>".$row[$attribute]."<td>";
}
echo '</tr>';
}
echo '</tbody></table>';
有一个屏幕截图显示表格当前的样子
如果我使用var_dump($analysis data)
它看起来像
array(9) { [0]=> array(2) { ["country"]=> string(30) "Germany " ["counter"]=> int(34) } [1]=> array(2) { ["country"]=> string(30) "Vorarlberg " ["counter"]=> int(2) } [2]=> array(2) { ["country"]=> string(30) "Oberoesterreich " ["counter"]=> int(9) } [3]=> array(2) { ["country"]=> string(30) "Wien " ["counter"]=> int(5) } [4]=> array(2) { ["country"]=> string(30) "Switzerland " ["counter"]=> int(3) } [5]=> array(2) { ["country"]=> string(30) "Salzburg " ["counter"]=> int(6) } [6]=> array(2) { ["country"]=> string(30) "Niederoesterreich " ["counter"]=> int(1) } [7]=> array(2) { ["country"]=> string(30) "Czech Republic " ["counter"]=> int(3) } [8]=> array(2) { ["country"]=> string(30) "Steiermark " ["counter"]=> int(1) } }
有人知道这些空单元格来自哪里以及如何删除它们吗?
神不在的星期二