+ 4
Why should we use '&&' and '||' operator while they works same as 'and' and 'or'? Someone please explain
11 Answers
+ 4
&& has higher precedence than and.
example:
if $ a is true and $ b is false
then for
$ c= $ a && $ b
c will be false as && has greater precedence than =.
but for
$ c= $ a and $ b
c will be true as and has lower precedence than =.
+ 1
May be they are options to each other. ...v don't have to use them compulsarily
+ 1
There is a very subtle difference between & and &&, even though the results will be same for a given expression. For eg. if the exp is a&&b, the compiler will just check for the left side; if the left side is false it declares the exp false without checking for the other side. Similarly for a||b, if the compiler finds a to be true it declares the whole exp true without bothering about other. On the other hand & and | always force the compiler to check both sides of the operator no matter what the situation. If you want to go even more technically, & and | are used for manipulating bits (outside context and scope) , and in almost all conditional statements && and || are generally used.
0
both AND and && can use for that symbolic representation is that
0
&& same as AND, || same as OR
0
for convenient purpose. ..you can use any one...depends on your choice.
0
Just an alternative way I believe.
0
If you're used to programming you'd use '&&' and '||' as they're common among other languages, but 'and' and 'or' would make more sense for someone who's only getting started or maybe only interested in learning php alone ;)
0
check the documentation
http://php.net/manual/en/language.operators.logical.php
0
"||" and "&&" have a greater precedence than "or" and "and"