elmas156 Posted November 23, 2014 Share Posted November 23, 2014 Which is better, option 1 or option 2? Option 1: $updated = "n"; if ($v1 == "y") { Do something with $v1; $udpated = "y"; } if ($v2 == "y") { Do something with $v2; $updated = "y" } OR Option 2: if ($v1 == "y" && $v2 == "y") { Do something with $v1 and $v2; $updated = "y"; } elseif ($v1 == "y" && $v2 == "n") { Do something with $v1, but not $v2; $updated = "y"; } elseif ($v1 == "n" && $v2 == "y") { Do something with $v2, but not $v1; $updated = "y"; } elseif ($v1 == "n" && $v2 == "n") { Don't do anything with $v1 or $v2; $updated = "n"; } I've used both methods, and they both work, but I'm not sure which one is the best to use. Does if even really matter? Thanks for your opinion. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 23, 2014 Share Posted November 23, 2014 I like option 1 Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted November 23, 2014 Solution Share Posted November 23, 2014 Depends on what the "something" that you are doing is. If the something that you do to v1 is always independent of what the value of v2 is, then option 1. If, however, that something also depends on the value of v2 then you have to go with option 2. Quote Link to comment Share on other sites More sharing options...
elmas156 Posted November 23, 2014 Author Share Posted November 23, 2014 Thanks! 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.