Created
March 26, 2012 18:54
-
-
Save tomkrush/2208677 to your computer and use it in GitHub Desktop.
Simple Dropdown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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