在php中,有这样两对运算符:|| , &&; or , and
请问这两组运算符的优先级是怎么样的?
相同优先级的运算符是从左到右结合的吗?
$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";
输出: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";
输出:true false
可以解释一下为什么是这样的结果吗?
|| > and > or
$a = true;
$b = true;
$c = false;
if($a or $b and $c) echo "true"; //相当于 if($a or ($b and $c))
else echo "false";
echo "<br />";
if($a || $b and $c) echo "true"; //相当于 if (($a || $b) and $c)
else echo "false";