【发布时间】:2013-04-13 10:57:07
【问题描述】:
我是 PHP 新手,我正在尝试使用两个 foreach 制作一个表格,但没有得到我想要的输出。
<html>
<head>
<title>Didier Test</title>
</head>
<body>
<h1>Yesso!</h1>
</body>
<table border="1">
<tr>
<th>Books</th>
<th>Price</th>
</tr>
<tr>
<?php foreach($name as $item): ?>
<td><?=$item?></td>
<?php foreach($price as $item2): ?>
<td><?=$item2?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</table>
</body>
</html>
我知道我的内部 foreach 有问题,但我不知道如何纠正它。
请告诉我。
【问题讨论】:
-
哪个问题?怎么了?
-
您的循环可能不起作用,因为您的变量中没有数据。请使用
var_dump($name, $price)并向我们展示结果。这些必须是数组才能使循环工作。
标签: php html foreach html-table