亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當填充 PHP 數組時 HTML 表中的空單元格

當填充 PHP 數組時 HTML 表中的空單元格

PHP
心有法竹 2023-08-11 17:58:14
我剛剛用 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) } }有人知道這些空單元格來自哪里以及如何刪除它們嗎?
查看完整描述

1 回答

?
神不在的星期二

TA貢獻1963條經驗 獲得超6個贊

修復你的 html 標記:


// Create `thead` for header and open `tr` for first row

echo "<table id='data' style='border: 1px solid black'><thead><tr>";

echo "<th>Country </th>";

echo "<th>Counter</th>";


// Close `tr` and `thead`, open `tbody`

echo "</tr></thead><tbody>";


foreach($analysis_data as $row){

    echo "<tr>";

    foreach(['country','counter'] as $attribute){

        echo "<td>".$row[$attribute]."</td>";    // close `td` here

    }

    echo '</tr>';

}

echo '</tbody></table>';


查看完整回答
反對 回復 2023-08-11
  • 1 回答
  • 0 關注
  • 137 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號