Jump to content

Quick SimpleQuestion


Go to solution Solved by Barand,

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/292658-quick-simplequestion/
Share on other sites

  • Solution

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.