【发布时间】:2016-05-08 10:55:01
【问题描述】:
我是 PHP 新手,一直试图理解这个基本的 while/for 循环。我只是想澄清几件事。这是代码:
while ($row = $sth->fetch (PDO::FETCH_NUM))
{
print ("<tr>\n");
for ($i = 0; $i < $sth->columnCount (); $i++)
{
print ("<td>" . htmlspecialchars ($row[$i]) . "</td>\n");
}
print ("</tr>\n");
}
我知道 while 正在评估 true,所以它正在获取查询的结果集,然后打印标签。
但是我卡在了
for ($i = 0; $i < $sth->columnCount (); $i++)
我知道第一个表达式计算一次,第二个在开始时计算,只有在它为真时才继续,第三个增加 +1。但从字面上看,这到底是做什么的,为什么是“columnCount”?
【问题讨论】:
标签: php loops for-loop while-loop