maxim Posted April 20, 2007 Share Posted April 20, 2007 if have what will be a easy q for most of you. consider the following code if (0 and 1 > -1) { print "true"; } that if statment will never be read. im not sure why, my guess is because PHP thinks the 0 is false ?? this code how ever will work as expected if (1 and 0 > -1) { print "true"; } any one care to explain why. is it precedence ? Link to comment https://forums.phpfreaks.com/topic/47828-and-operator/ Share on other sites More sharing options...
Glyde Posted April 20, 2007 Share Posted April 20, 2007 Because 0, when not being compared to anything else, is false. 0 can be compared to other integers using <, <=, >=, >, ==, ===, !=, !==, but in a standalone state all of the following are false: "" (an empty string) "0" (a string containing only 0) 0 (0 as an integer) Link to comment https://forums.phpfreaks.com/topic/47828-and-operator/#findComment-233689 Share on other sites More sharing options...
pocobueno1388 Posted April 20, 2007 Share Posted April 20, 2007 I don't think you can use the and operator in an IF statement like that....not positive though. You would have to do something like this: if ((1 > -1) && (0 > -1)){ print 'true'; } Link to comment https://forums.phpfreaks.com/topic/47828-and-operator/#findComment-233694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.