I'm getting post values from an emailer form and I set all the option values to numbers and I'm trying to convert them to their actual strings to send in an email. I need to make this code easier to use.
if ($subject == "1") {
$sub = "General Questions";
} elseif($subject == "2") {
$sub = "Membership";
} elseif($subject == "3") {
$sub = "Club Fees";
} elseif($subject == "4") {
$sub = "Proshop & Lessons";
} elseif($subject == "5") {
$sub = "Events";
} elseif($subject == "6") {
$sub == "Leagues & Programs";
} elseif($subject == "7") {
$sub == "Resturant & Bar";
};
Maybe I could set the value=''
to the actual values and skip this part all together.
Why not make an associative array?
$subs = array(
1 => 'General Questions',
2 => 'Membership',
3 => 'Club Fees',
4 => 'Proshop & Lessons',
// others.
);
$sub = isset($subs[$subject]) ? $subs[$subject] : 'Default Value';
One way to rewrite is to use the switch
statement in PHP. You can read more about it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With