The easiest way I can think of is this:
Php
<?php $selection=array('PHP','ASP'); echo '<select> <option value="0">Please Select Option</option>'; foreach($selection as $selection){ $selected=($options == $selection)? "selected" : ""; echo '<option '.$selected.' value="'.$selection.'">'.$selection.'</option>'; } echo '</select>';
The code basically puts all your parameters in an array that is called in a foreach loop. The loop checks to see if your $ options variable matches the currently selected item, if it matches, and then $ selected will = be selected, if not, it will be empty. Finally, an option tag is returned containing the selection from the array, and if that particular selection is equal to your $ options variable, it is set as the selected option.
source share