0

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

1 Answer 1

10

$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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.