php - Will it make any diffrence to my script if i use && instead of AND?
150
Can any one tell, will it make any difference if I use && operator for condition instead of and in my php script?
For e.g
if($i == 1 and $bool == true)
is same as
if($i == 1 && $bool == true)
It will be better if anyone tell me difference between them.
Answer
Solution:
The difference between
&&
andand
is precedence:&&
has a higher one.If you evaluate boolean expressions, I would stick with the most common used:
&&
and.
Update:
Example:
evaluates as
whereas
evaluates as
Answer
Solution:
The only difference is operator precendence, i.e if you mix and match types which ones are evaluted first.
See http://www.php.net/manual/en/language.operators.logical.php
Answer
Solution:
php being the frankenlanguage that it is, I would personally fall back on my General Orders:
Answer
Solution:
There is precedence issue only about using whether && or And, Moreover i recommend you to use && in numerical type comparisons and phrase comparisons "And", "Or". These make more sense to me. they'll increase the readability in your code.