Friday, June 28, 2019

conditional - PHP - and / or keywords



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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...