在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
可以解释一下为什么是这样的结果吗?

解决方案 »

  1.   

    && -> || -> and -> or没有相同优先级 $a or $b and $c  // true or (true and false) $a || $b and $c // (true || false) and false
      

  2.   

    优先级:http://www.php.net/manual/zh/language.operators.precedence.php
    || > 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";