Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will it make any diffrence to my script if i use && instead of AND?

Tags:

php

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.

like image 238
Poonam Bhatt Avatar asked Feb 25 '23 19:02

Poonam Bhatt


2 Answers

The difference between && and and is precedence: && has a higher one.

If you evaluate boolean expressions, I would stick with the most common used: && and ||.

Update:

Example:

a || b and c

evaluates as

(a || b) and c

whereas

a || b && c

evaluates as

a || (b && c)
like image 163
Felix Kling Avatar answered Apr 07 '23 02:04

Felix Kling


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

like image 40
neopickaze Avatar answered Apr 07 '23 03:04

neopickaze