0

知道为什么我不能在循环外回显 $a 吗?我错过了什么?

while (list($a) = $db->fetch_array($query))
{
     $b = $a; //where $a = 10
}

echo $a; //this echo's nothing.
echo $b; //this echo's 10
4

1 回答 1

10

$a重置为NULLwhile 循环结束时,因此它不输出任何内容。(此时不再进入循环,因此$b = $a不再执行)

这是因为$db->fetch_array()当没有剩余行时返回 false。

于 2013-07-22T07:33:31.107 回答