Is &&
the same as "and", and is ||
the same as "or" in PHP?
I've done a few tests, and it seems they behave the same. Are there any differences?
If not, are there any other PHP signs that have word equivalents and do you think it makes the code easier to read?
Answer
and
and or
have higher lower precedence than &&
and ||
. To be more exact &&
and ||
have higher precedence than assignment operator ( =
) while and
and or
have lower.
http://www.php.net/manual/en/language.operators.precedence.php
Usually it doesn't make a difference, but there are cases when not knowing about this difference can cause some unexpected behaviour. See examples here:
http://php.net/manual/en/language.operators.logical.php
No comments:
Post a Comment