在PHP中使用赋值运算符进行while循环 [英] while loop in php with assignment operator

查看:116
本文介绍了在PHP中使用赋值运算符进行while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看的代码可以做到这一点...

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

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

我想知道while语句的作用是什么?它里面有一个赋值运算符,因此只要$ info被赋值为false以外的值,该代码就会执行吗?

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?

推荐答案

[... S] o,只要为$ info分配了除false以外的其他值,该代码就会执行?

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

是的,是的.即使该表达式中有一个赋值运算符,该表达式本身仍代表一个值.在这种情况下,整个表达式的结果等于对$info的赋值.换句话说:该表达式与$info 相同,或者该表达式已分配给$info-最后一个变体也许是最好的描述.

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.

因此,现在每当$info等于true时,将执行while中的代码块.

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

请记住,比较是宽松比较.因此,不仅false还是NULL或一个空数组都将停止内部代码块的执行.

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.

这篇关于在PHP中使用赋值运算符进行while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆