public static function select($name, $options_array, $key_as_value=true, $selected="!NO!")
{
$html = "<select name='$name'>\n";
foreach($options_array as $key => $val)
{
$option_value = ($key_as_value) ? $key : $val;
$option_display = $val;
$selected = ($selected != "!NO!" && $selected == $option_value) ? " SELECTED" : "";
$option = "<option value='$option_value'$selected>$option_display</option>\n";
$html .= $option;
}
$html .= "</select>\n";
return $html;
}
This is my PHP code that generates a SELECT element, if you pass $selected it will have the desired option selected. The problem is, having the default value as "!NO" looks very ugly. But I can't make it as FALSE either because FALSE is synonim for 0 and if there is an option with value "0" it won't work as expected.
Any suggestions for this?