AND [和] &&之间的区别

Rya*_*yan 3 php logical-operators

鉴于声明:

if($value && array_key_exists($value, $array)) {

         $hello['world'] = $value;

        }
Run Code Online (Sandbox Code Playgroud)

是否最好使用逻辑运算符AND而不是&&?

the*_*ega 11

就他们自己而言,他们完全一样.所以a && b意味着相同a and b.但是,它们并不相同,&&优先级高于and.有关详细信息,请参阅文档.

这个例子显示了不同之处:

// 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) and true)
$f = false and true;
Run Code Online (Sandbox Code Playgroud)