lukelee Posted December 5, 2008 Share Posted December 5, 2008 I am confusing about the php operator, are these 2 if conditions the same? if(($filesize1 && $filesize2 && $filesize5 != 0) && ($filesize3 ==0)&& ($filesize4 ==0)) if(($filesize1 && $filesize2 && $filesize5 != 0) && ($filesize3 && $filesize4 ==0)) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2008 Share Posted December 5, 2008 The distributive property is only valid in algebra, not in programming logic - http://www.icoachmath.com/SiteMap/DistributiveProperty.html Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 5, 2008 Share Posted December 5, 2008 The distributive property is only valid in algebra, not in programming logic - http://www.icoachmath.com/SiteMap/DistributiveProperty.html It's as valid in programming, as it is in algebra. $a && ($b || $c) == ($a && $b) || ($a && $c) But! $filesize3 && $filesize4 == 0 is not the same as ($filesize3 == 0) && ($filesize4 == 0) and I believe lukelee is after the second one. $filesize3 && $filesize4 == 0 first evaluates $filesize3 && $filesize4 and then compares the result to 0 Quote Link to comment Share on other sites More sharing options...
lukelee Posted December 5, 2008 Author Share Posted December 5, 2008 The distributive property is only valid in algebra, not in programming logic - http://www.icoachmath.com/SiteMap/DistributiveProperty.html It's as valid in programming, as it is in algebra. $a && ($b || $c) == ($a && $b) || ($a && $c) But! $filesize3 && $filesize4 == 0 is not the same as ($filesize3 == 0) && ($filesize4 == 0) and I believe lukelee is after the second one. $filesize3 && $filesize4 == 0 first evaluates $filesize3 && $filesize4 and then compares the result to 0 the second one is to compare$filesize3 and $filesize4, does that mean $filesize3 == $filesize4? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted December 5, 2008 Share Posted December 5, 2008 $filesize3 && $filesize4 == 0 first evaluates $filesize3 && $filesize4 and then compares the result to 0 Not quite. The == operator has a higher precedence than the && operator. Therefore, $filesize3 would first be evaluated, then $filesize4 == 0 would be evaluated assuming $filesize3 is true, owing to shortcut evaluation. Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 Not quite. The == operator has a higher precedence than the && operator. Therefore, $filesize3 would first be evaluated, then $filesize4 == 0 would be evaluated assuming $filesize3 is true, owing to shortcut evaluation. That's why I overuse () in conditions Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.