Jump to content

if($any_variable == '0'){$any_variable = "No";}


tekrscom

Recommended Posts

I was wondering, if you have several instances in which you use the same method of conversion for all variables from your database to your code, is there a way to effect them all, i.e.;

if($any_variable == '0'){$any_variable = "No";}
if($any_variable == '1'){$any_variable = "Yes";}

or

if($any_variable == '0'){$any_variable = "Pending";}
if($any_variable == '1'){$any_variable = "Closed";}

or

if($any_variable == '0'){$any_variable = "";} // Was also curious about this, is there a better way, instead of just using empty quotes, like some way to destroy the variable so it doesn't show anything?
if($any_variable == '1'){$any_variable = "Here is whatever";}

 

Its just that when you have to repeat this several times, for several different variables, it seems to make for alot of extra strung around code.

Link to comment
https://forums.phpfreaks.com/topic/48455-ifany_variable-0any_variable-no/
Share on other sites

Was also curious about this, is there a better way, instead of just using empty quotes, like some way to destroy the variable so it doesn't show anything?

 

http://us2.php.net/unset

 

I'm not really sure what the first part of your question is asking.

 

Best,

 

Patirck

ohya... also with...

 

if($any_variable == '0'){$any_variable = "No";}
if($any_variable == '1'){$any_variable = "Yes";}

 

you prolly want to code it this way... its alot faster ;-)...

 

switch($any_variable){
case "0":
  $any_variable="No";
break;
case "1":
  $any_variable="Yes";
break;
}

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.