<?
$a=true;
$b=true;
$c=false;
if($a or $b and $c)
echo"true";
else
echo"false";
echo "<br>";
if($a || $b and $c)
echo"true";
else
echo"false";
?>
or和||都是逻辑或,优先级不一样,为什么输出的结果,一个为true,一个为false?
$a=true;
$b=true;
$c=false;
if($a or $b and $c)
echo"true";
else
echo"false";
echo "<br>";
if($a || $b and $c)
echo"true";
else
echo"false";
?>
or和||都是逻辑或,优先级不一样,为什么输出的结果,一个为true,一个为false?
if($a || ($b and $c)) 由此得出一个结论,那就是||和or,以及and和&&不可混用,除非自己很清楚此权重问题
$a=true;
$b=true;
$c=false;
// 运算符的优先级 && > || > and > or
if($a or $b and $c) // 相当于 $a or ($b and &c) => true if($a || $b and $c) // 相当于 ($a || $b) and $c => false
或者直接用 () 起来