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

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

如何訪問數組中的值并將它們放入html表中

如何訪問數組中的值并將它們放入html表中

PHP
倚天杖 2022-06-11 19:00:18
我只想將數據放入第二列。每個人都有這個的源代碼嗎?我想像這樣將逗號分隔的值放入 html 表中
查看完整描述

2 回答

?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

以下是如何輸出數組的全部內容,而無需指定數組的鍵


<!DOCTYPE html>

<html>

<head>

<!-- Your stylesheet here -->

</head>


<body>


<h2>My cool table</h2>


<table>

<tr>

  <th>Items</th>

  <th>Stocks</th>

<tr>


<?php


// Create the array

$myArray=array('TV' => '1', 'Speaker' => '34', 'Radio' => '11');


// Output all of the items in the table

foreach($myArray as $item => $stock){

echo "<tr><td>{$item}</td><td>{$stock}</td></tr>";

}


?>


</table>


</body>

</html>

輸出應類似于以下內容:


<!DOCTYPE html>

<html>

<head>

<!-- Your stylesheet here -->

</head>


<body>


<h2>My cool table</h2>


<table>

<tr>

  <th>Items</th>

  <th>Stocks</th>

<tr>


<tr><td>TV</td><td>1</td></tr><tr><td>Speaker</td><td>34</td></tr><tr><td>Radio</td><td>11</td></tr>

</table>


</body>

</html>


查看完整回答
反對 回復 2022-06-11
?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

<html>



<?php 

$key = array(1,2,3);

?>


<table >

  <thead>

    <th>a</th>

    <th>b</th>

  </thead>

  <tbody>

    <tr>

      <td>c</td>

      <td><?php echo $key[0]?></td>

    </tr>

    <tr>

      <td>d</td>

      <td><?php echo $key[1]?></td>

    </tr>


  </tbody>

</table>


</html>

要訪問數組,請使用 $variable_name[position]。


查看完整回答
反對 回復 2022-06-11
  • 2 回答
  • 0 關注
  • 198 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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