Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

while loop in php with assignment operator

the code I'm looking at does this...

while ($info=mysql_fetch_array($data_jurisdiction))
{
//some stuff
}

I'm wondering what does this while statement do? it has an assignment operator within it, so as long as $info gets assigned a value other than false, this code will execute?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

[... S]o as long as $info gets assigned a value other than false, this code will execute?

Quite, yes. Even there is an assignment operator within that expression, the expression itself still stands for a value. In this case the result of the whole expression is equal to the assignment to $info. In other words: The expression is the same as $info or the expression has been assigned to $info - the last variant is perhaps the best description.

So now whenever $info equals to true, the code block inside while will be executed.

Keep in mind that the comparison is a loose comparison. So not only false but as well NULL or an empty array will stop the execution of the inner code-block.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...