Skip to content

Instantly share code, notes, and snippets.

@mewm
Created May 19, 2013 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mewm/5608706 to your computer and use it in GitHub Desktop.
Save mewm/5608706 to your computer and use it in GitHub Desktop.
<?php
//Define options
$options = new ArrayObject(array(
'a',
'b',
'c',
'd',
'e',
'f'
));
?>
<select name="hlength">
<?php
$chosenValue = (isset($value['hl']) ? $value['hl'] : null); //The value defined here will be the selected one
echo '<option value="">Unable to determine</option>'; //Default, and top option
//Iterate options
foreach ($options->getIterator() as $value) {
echo '<option'. (($value == $chosenValue) ? ' selected="selected"' : '') .' value="'. $value .'">'. $value .'</option>';
}
?>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment