The difference is on the precedence. But not only compared with each other!
In most cases you won't mind it, but there are specific cases when you have to take one step back and look at the big picture. Take this, for example:
// 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 before the "and" operation occurs
// Acts like: (($h = true) and false)
$h = true and false;
var_dump($g, $h);
This will produce, respectively:
bool(false)
bool(true)
In other words, &&
has higher preference than =
, which has higher precedence than and
, as stated in http://php.net/manual/en/language.operators.precedence.php. (It is mentioned in other answers, but I think it's worth to detail, since a misuse can lead to logical errors)
I hope it may help you. You can find more at http://php.net/manual/en/language.operators.logical.php
&&
is AND, but&
is AND (bitwise). Liekwise for||
and|
are OR and OR (bitwise), respectively. :: I take it back, PHP allows AND/OR words--amazing. Learn something new every day. – Brad Christie||
and&&
more readable, but I'd expect others to disagree. Stick with the convention of the environment you find yourself in. – Thomas Langston