Jump to content

Quick SimpleQuestion


elmas156

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

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.

Archived

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

×
×
  • 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.