17

Possible Duplicate:
PHP - and / or keywords

Dear All,

I would like to get clear in mind about conditional operators in php. Please clarify me what is the difference between '&&' and 'AND' in php?

Thanks in Advance

Community
  • 1
  • 1
A.C.Balaji
  • 1,053
  • 4
  • 13
  • 23

1 Answers1

20

They do the same thing, but && has higher precedence than AND.

http://php.net/manual/en/language.operators.precedence.php

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • 4
    While correct, pick one style and stick to it. Unless you LIKE leaving code bombs for people to blow limbs off with. – DampeS8N Dec 22 '10 at 16:35
  • Dear Dampe, I couldn't understand what would you like to say. – A.C.Balaji Dec 22 '10 at 16:38
  • 1
    @JimMischel Try the following: `define( 'THIS', true ); $test_a = defined( 'THIS' ) AND THIS ? 'A: success' : 'A: no success'; $test_b = defined( 'THIS' ) AND THIS ? 'A: success' : 'A: no success'; var_dump( $test_a ); echo '
    '; var_dump( $test_b );`. If I'm not wrong, then `$test_a` is `TRUE` and `$test_b` would be `A success`, right?
    – kaiser Jan 24 '12 at 06:40
  • @kaiser no, they are both `bool (true)` – Joshua Smickus Nov 29 '13 at 15:53
  • 1
    An easier example: `$a = 1 AND 1 OR false; $b = 1 && 1 OR false;` After this `$a` will be == 1 (and the rest of the expression is just omitted), while `$b` will be == true because this is the result of the whole expression. – Oleg Dubas Jan 27 '14 at 01:19
  • 4
    The easiest example: `$a = true AND false;`. Can you guess the $a? It will be = TRUE !!! – Oleg Dubas Jan 27 '14 at 01:25