I have a simple html form with select element. To define which option is selected, I add selected as
<option value="10" <?php if($value == '10') {echo 'selected="selected"';}?>>10</option>
<option value="20" <?php if($value == '20') {echo 'selected="selected"';}?>>20</option>
<option value="50" <?php if($value == '50') {echo 'selected="selected"';}?>>50</option>
$value is a variable which comes from PHP codes. This methods seems to be very simple and naive. Is it the best way to do so?
Not a bad way to do it. But why not create the entire thing using programmatic approach (i.e., generate the code using a PHP loop through an array):