Difference between && and and operator in PHP

This question already has an answer here:

  • 'AND' vs '&&' as operator 10 answers

  • "&&" has a greater precedence than "and"

    // The result of the expression (true && false) is assigned to $g
    // Acts like: ($g = (true && false))
    $g = true && false;
    
    // The constant true is assigned to $h and then false is ignored
    // Acts like: (($h = true) and false)
    $h = true and false;
    
    var_dump($g, $h);
    

    prints false, true


    They are the same except for Precedence

    && > = > and in the precedence table so your first example is equivalent to: ($test = true) and false;

    链接地址: http://www.djcxy.com/p/57606.html

    上一篇: &&和'和'在php中是一样的吗?

    下一篇: PHP中&&与运算符的区别