Reputation: 2619
Any idea why i can't echo $a outside the loop? what am i missing?
while (list($a) = $db->fetch_array($query))
{
$b = $a; //where $a = 10
}
echo $a; //this echo's nothing.
echo $b; //this echo's 10
Upvotes: 0
Views: 76
Reputation: 23777
$a
is reset to NULL
when the while loop ends, so it outputs nothing. (and the loop isn't entered at this moment anymore, so $b = $a
won't be executed anymore)
This is because $db->fetch_array()
returns false when there are no rows left.
Upvotes: 10