1

これは奇妙なものです。WordPressのPHPテーマファイル内で作業しています。

$a = false;
$b = true;

$c = $a OR $b;

$cはfalse

だが

$c = $a || $b;

$ cは、正しくはtrue

関数を作成できます

function checkor($a, $b)
{
  return $a OR $b;
}

そして、これは上記の値に対して正しく戻りtrueます。

phpORオペランドがWordPressテーマテンプレートファイルで機能しないように見える理由はありますか?(私はMac、PHPバージョン5.2.13でMAMP Proを実行しています。)

4

2 に答える 2

3

PHP マニュアルを確認してください http://www.php.net/manual/en/language.operators.logical.php

// "||" has a greater precedence than "or"

// The result of the expression (false || true) is assigned to $e
// Acts like: ($e = (false || true))
$e = false || true;

// The constant false is assigned to $f and then true is ignored
// Acts like: (($f = false) or true)
$f = false or true;
于 2012-09-03T20:01:36.410 に答える
2

これは Wordpress とは関係なく、実際に PHP が動作する方法です。
これはOperator Precedenceと呼ばれます。

PHPドキュメントを引用するには:

// "||" has a greater precedence than "or"

// The result of the expression (false || true) is assigned to $e
// Acts like: ($e = (false || true))
$e = false || true;

// The constant false is assigned to $f and then true is ignored
// Acts like: (($f = false) or true)
$f = false or true;
于 2012-09-03T20:01:09.410 に答える