【发布时间】:2017-07-26 05:42:04
【问题描述】:
我开始学习 PHP,我的循环有时会遇到问题,主要是 for 循环。由于某种神秘的原因,我在循环中回显的内容根本不会显示或显示。当我在编译 PHP 代码后查看源代码时,那里什么都没有。
这是我正在使用的代码。它应该显示一个 4 行 6 列的表格。但它不会发生。我做错了什么?
<table border="1" cellpadding="10">
<?php
$dato = date("d");
for ($teller = 0; $teller > 4; $teller++) {
echo "<tr>";
for ($teller2 = 0; $teller2 > 6; $teller2++) {
echo "<td>Luke<br></td>";
}
echo "</tr>";
}
?>
</table>
【问题讨论】:
-
循环永远不会运行,因为你指定了 - run loop while
$teller > 4是真的,但它永远不会是真的,因为 $teller 一开始是 0。 -
只要第二个表达式
$teller > 4为真,循环就会继续。你可能想要$teller < 4。有用的链接:php.net/manual/en/control-structures.for.php(编辑:迟到...)
标签: php loops html-table