Habari\Utils::html_select PHP Method

html_select() public static method

Create an HTML select tag with options and a current value
public static html_select ( string $name, array $options, string $current = null, array $properties = [] ) : string
$name string The name and id of the select control
$options array An associative array of values to use as the select options
$current string The value of the currently selected option
$properties array An associative array of additional properties to assign to the select control
return string The select control markup
    public static function html_select($name, $options, $current = null, $properties = array())
    {
        $id = isset($properties['id']) ? $properties['id'] : $name;
        $output = '<select id="' . $id . '" name="' . $name . '"';
        foreach ($properties as $key => $value) {
            $output .= " {$key}=\"{$value}\"";
        }
        $output .= ">\n";
        foreach ($options as $value => $text) {
            $output .= '<option value="' . $value . '"';
            if ($current == (string) $value) {
                $output .= ' selected="selected"';
            }
            $output .= '>' . $text . "</option>\n";
        }
        $output .= '</select>';
        return $output;
    }