0

I am know about priority, but if we have one simple condition:

if ($a == 1 AND $b == 2){

}

Is there any difference with

if ($a == 1 && $b == 2){

}

?

Andrey Vorobyev
  • 896
  • 1
  • 10
  • 37
  • No difference with `==`. Compare with [PHP operator precedence](http://php.net/manual/en/language.operators.precedence.php). – hakre Aug 12 '12 at 09:07
  • 2
    a bit OOT, what funny for me is, the fact that CI suggests users to use OR instead of ||, but choosing && instead of AND... such an inconsistency... – zfm Aug 12 '12 at 09:15

3 Answers3

5

There is no difference at all, except that perhaps using AND is somewhat more readable.

EDIT: just checked, and there is a small difference in the operators precedence, see http://php.net/manual/en/language.operators.precedence.php

Matteo Tassinari
  • 18,121
  • 8
  • 60
  • 81
4

They do the exact same thing. && has higher precedence that AND though.

This has been asked before:

PHP - and / or keywords

PHP : Difference between '&&' and 'AND'

Community
  • 1
  • 1
Brent Morrow
  • 1,044
  • 11
  • 18
1

The both work the same in php, but most programmers are used to using && as its the syntax used in most programming languages