tags:

views:

293

answers:

4

Can I use if(4 <= $a <= 44) instead of if(4 <= $a && $a <= 44)?

+4  A: 

No, you can't. 

if(4 <= $a <= 44) will (I believe) be parsed as if ((4 <= $a) <= 44), which checks whether (4 <= $a) (which is either 0 or 1) is less than 44.

SLaks
+8  A: 

No, you can't do that.

if(4 <= $a <= 44) is equivalent to if((4 <= $a) <= 44). This may be equivalent to if(false <= 44) or if(true <= 44), neither of which makes sense.

Svisstack
+4  A: 

No

Chacha102
+1  A: 

No, you can't (as all others already said).

Comparison operators in PHP, as their name implies, allow you to compare two values, and with the expression

4 <= $a <= 44

you would be comparing three values. Read here for a complete explanation.

eKek0