这是一种方法:
<?php
$otherproblem = "Aspirin";
$dropdown = array(
"Nothing",
"Allergy: Penicillin",
"Aspirin",
"Erythromycin",
"Latex or Rubber Products",
"Codeine",
"Tetracycline",
"Germicides/Pesticides, Foods",
"Other",
"Asthma",
"Bleeding Disorders",
"Diabetes",
"Epilepsy",
"GI disorders",
"Heart disease",
"Hepatitis",
"Jaundice",
"Liver disease",
"Neoplasm",
"Psychiatric Problems",
"Respiratory diseases",
"Rheumatic fever"
);
?>
<p>General Medical History:
<select name="otherproblem">
<?php foreach ($dropdown as $name): ?>
<option <?php if ($otherproblem == $name) print('selected="selected"');?> value="<?php print($name);?>"><?php print($name);?></option>
<?php endforeach; ?>
</select>
</p>
方式二:
<?php
$otherproblem = "Erythromycin";
?>
<p>General Medical History:
<select name="otherproblem">
<option <?php if($otherproblem == "Nothing"){print('selected="selected"');}?> value="Nothing">Nothing</option>
<option <?php if($otherproblem == "Allergy: Penicillin"){print('selected="selected"');}?> value="Allergy: Penicillin">Allergy: Penicillin</option>
<option <?php if($otherproblem == "Aspirin"){print('selected="selected"');}?> value="Aspirin">Aspirin</option>
<option <?php if($otherproblem == "Erythromycin"){print('selected="selected"');}?> value="Erythromycin">Erythromycin</option>
<option <?php if($otherproblem == "Latex or Rubber Products"){print('selected="selected"');}?> value="Latex or Rubber Products">Latex or Rubber Products</option>
<option <?php if($otherproblem == "Codeine"){print('selected="selected"');}?> value="Codeine">Codeine</option>
<option <?php if($otherproblem == "Tetracycline"){print('selected="selected"');}?> value="Tetracycline">Tetracycline</option>
<option <?php if($otherproblem == "Germicides/Pesticides, Foods"){print('selected="selected"');}?> value="Germicides/Pesticides, Foods">Germicides/Pesticides, Foods</option>
<option <?php if($otherproblem == "Other"){print('selected="selected"');}?> value="Other">Other</option>
<option <?php if($otherproblem == "Asthma"){print('selected="selected"');}?> value="Asthma">Asthma</option>
<option <?php if($otherproblem == "Bleeding Disorders"){print('selected="selected"');}?> value="Bleeding Disorders">Bleeding Disorders</option>
<option <?php if($otherproblem == "Diabetes"){print('selected="selected"');}?> value="Diabetes">Diabetes</option>
<option <?php if($otherproblem == "Epilepsy"){print('selected="selected"');}?> value="Epilepsy">Epilepsy</option>
<option <?php if($otherproblem == "GI disorders"){print('selected="selected"');}?> value="GI disorders">GI disorders</option>
<option <?php if($otherproblem == "Heart disease"){print('selected="selected"');}?> value="Heart disease">Heart disease</option>
<option <?php if($otherproblem == "Hepatitis"){print('selected="selected"');}?> value="Hepatitis">Hepatitis</option>
<option <?php if($otherproblem == "Jaundice"){print('selected="selected"');}?> value="Jaundice">Jaundice</option>
<option <?php if($otherproblem == "Liver disease"){print('selected="selected"');}?> value="Liver disease">Liver disease</option>
<option <?php if($otherproblem == "Neoplasm"){print('selected="selected"');}?> value="Neoplasm">Neoplasm</option>
<option <?php if($otherproblem == "Psychiatric Problems"){print('selected="selected"');}?> value="Psychiatric Problems">Psychiatric Problems</option>
<option <?php if($otherproblem == "Respiratory diseases"){print('selected="selected"');}?> value="Respiratory diseases">Respiratory diseases</option>
<option <?php if($otherproblem == "Rheumatic fever"){print('selected="selected"');}?> value="Rheumatic fever">Rheumatic fever</option>
</select>
</p>