Skip to content

Instantly share code, notes, and snippets.

@tomkrush
Created March 26, 2012 18:54
Show Gist options
  • Save tomkrush/2208677 to your computer and use it in GitHub Desktop.
Save tomkrush/2208677 to your computer and use it in GitHub Desktop.
Simple Dropdown.
function dropdown($name, $options, $value, $keys = FALSE, $attrs = array()) {
$attributes = array();
foreach($attrs as $key => $attr)
{
$attributes[] = $key."=\"".$attr."\"";
}
echo '<select name="'.$name.'" '.implode(' ', $attributes).'>';
if ( $keys == TRUE )
{
foreach($options as $key => $option) {
if ( $value == $key ) {
echo '<option value="'.$key.'" selected="selected">'.$option.'</option>';
}
else {
echo '<option value="'.$key.'">'.$option.'</option>';
}
}
}
else
{
foreach($options as $option) {
if ( $value == $option ) {
echo '<option value="'.$option.'" selected="selected">'.$option.'</option>';
}
else {
echo '<option value="'.$option.'">'.$option.'</option>';
}
}
}
echo '</select>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment