I have in my php
$sel = "
<option> one </option>
<option> two </option>
<option> thre </option>
<option> four </option>
";
let say I have an inline URL = site.php?sel=one
if I didn't saved those options in a variable, I can do it this way to make one of the option be SELECTED where value is equal to $_GET[sel]
<option <?php if($_GET[sel] == 'one') echo"selected"; ?> > one </option>
<option <?php if($_GET[sel] == 'two') echo"selected"; ?> > two </option>
<option <?php if($_GET[sel] == 'three') echo"selected"; ?> > three </option>
<option <?php if($_GET[sel] == 'four') echo"selected"; ?> > four </option>
but the problem is, I need to save those options in a variable because I have a lot of options and I need to call that variable many times.
Is there a way to make that option be selected where value = $_GET[sel]
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…