如何访问数组中的值并将它们放入html表中

我只想将数据放入第二列。每个人都有这个的源代码吗?我想像这样将逗号分隔的值放入 html 表中


倚天杖
浏览 175回答 2
2回答

动漫人物

以下是如何输出数组的全部内容,而无需指定数组的键<!DOCTYPE html><html><head><!-- Your stylesheet here --></head><body><h2>My cool table</h2><table><tr>&nbsp; <th>Items</th>&nbsp; <th>Stocks</th><tr><?php// Create the array$myArray=array('TV' => '1', 'Speaker' => '34', 'Radio' => '11');// Output all of the items in the tableforeach($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>&nbsp; <th>Items</th>&nbsp; <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>

白衣染霜花

<html><?php&nbsp;$key = array(1,2,3);?><table >&nbsp; <thead>&nbsp; &nbsp; <th>a</th>&nbsp; &nbsp; <th>b</th>&nbsp; </thead>&nbsp; <tbody>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td>c</td>&nbsp; &nbsp; &nbsp; <td><?php echo $key[0]?></td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td>d</td>&nbsp; &nbsp; &nbsp; <td><?php echo $key[1]?></td>&nbsp; &nbsp; </tr>&nbsp; </tbody></table></html>要访问数组,请使用 $variable_name[position]。
打开App,查看更多内容
随时随地看视频慕课网APP