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>
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]。
- 2 回答
- 0 关注
- 174 浏览
添加回答
举报