Logical Operators に関するphp.net Webページによると:
これ:
$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) // foo = undefined or foo = 5, so foo = 5
最後の例では、undefined は基本的に false に似ているため、foo は 5 に等しくなります。
また、演算子の優先順位のリンクは次のとおりです: http://www.php.net/manual/en/language.operators.precedence.php
アップデート:
では、本題に入りましょう。フェッチされたクエリを使用するときは、次のように知っています。
while($row = @mysql_fetch_assoc($result))
while ループは でのみ実行される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 (真のステートメントであるため) です。
誰もが理解できることを願っています。