Jump to content

If statement efficiency


ShadowMage
 Share

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 ||?

Edited by thescientist
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...