按照关于逻辑运算符的php.net网页:
这个:
复制代码 $e = false || true ;
这样的行为:
复制代码 $e = (false || true ) // If false is true , then $e = false . Otherwise true
这个:
复制代码 $f = false or true ;
会像这样:
复制代码 ($f = false ) or true ; // $f = false is true , as the assignment succeeded
这个:
复制代码 $foo or $foo = 5 ;
会像这样:
复制代码 $foo or ($foo = 5 )
对于最后一个,undefined基本上类似于false,因此foo等于5。
另外,这是运算符优先顺序的链接:[http://www.php.net/manual/zh/language.operators.precedence.php]
更新:
好的,现在让我们进入重点。 就像我们都知道使用提取的查询时一样:
复制代码 while ($row = @mysql_fetch_assoc($result))
众所周知,虽然循环仅在true
上执行,所以$row = @mysql_fetch_assoc($result)
返回true。
与达里奇的问题相同。
复制代码 $foo or $foo = 5 ;
基本上是:
复制代码 $foo or ($foo = 5 );
基本上是:
复制代码 $foo = undefined or ($foo = 5 ); // $foo = 5 actually returns true
这也是
复制代码 $foo = undefined or true ;
正如我前面提到的,undefined = false,因此$ foo = 5(因为这是正确的语句)。
希望大家都能理解。