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 關注
- 198 瀏覽
添加回答
舉報