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
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.