Jump to content

If statement efficiency


ShadowMage

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...