ShadowMage Posted February 16, 2011 Share Posted February 16, 2011 I was just curious, which is more efficient:if (!empty($var) && !empty($var))orif (!(empty($var) || empty($var))I'm inclined to believe that the second one would be slightly more efficient as there would be one less comparison/evaluation made. Correct? Link to comment Share on other sites More sharing options...
thescientist Posted February 16, 2011 Share Posted February 16, 2011 do you mean the second one would more efficient in the event the first case is met, thus not having to bother with the other side of the ||? Link to comment Share on other sites More sharing options...
jeffman Posted February 16, 2011 Share Posted February 16, 2011 I think he means that the first version could require two NOT operations. Either version can result in one or two executions of empty. Link to comment Share on other sites More sharing options...
ShadowMage Posted February 16, 2011 Author Share Posted February 16, 2011 do you mean the second one would more efficient in the event the first case is met, thus not having to bother with the other side of the ||?Well, actually I was thinking more about the ! operator, but I never thought about ignoring the second case...The ! operator would only have to be evaluated once for the whole expression, rather than once for each time empty() is called. Link to comment Share on other sites More sharing options...
ShadowMage Posted February 16, 2011 Author Share Posted February 16, 2011 I think he means that the first version could require two NOT operations. Either version can result in one or two executions of empty.So you are confirming my theory, then? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.