Is there a more efficient way to do this?
<? if ($service == oral) { echo $oral; } else if ($service == periodontics) { echo $periodontics; } else if ($service == restore) { echo $restore; } else if ($service == cosmetic) { echo $cosmetic; } else if ($service == endodontics) { echo $endodontics; } else if ($service == anesthesia) { echo $anesthesia; } else if ($service == other) { echo $other; } ?>
Thanks in advanced Aaron
Try a case statement.... much cleaner..
<? switch($service) { case "oral": echo $oral; break; case "periodontics": echo $periodontics; break; case "restore": echo $restore; break; case "cosmetic": echo $cosmetic; break; etc.... } ?>
i am assumming that $service is a string...
that works, but theres no like 1 line command?
No one liners for this. Your best bet is the switch statement.
<? $allowed = array('periodontics','restore','cosmetic','endodontics','anesthesia','other'); if(in_array($service,$allowed)) { echo $$service; } else { echo "Please select an item from the list.<br />\n"; } ?>