Redaxscript\Html\Form::_createOption PHP Method

_createOption() protected method

create the option
Since: 3.0.0
protected _createOption ( array $optionArray = [], mixed $selected = null ) : string
$optionArray array options of the select
$selected mixed option to be selected
return string
    protected function _createOption($optionArray = [], $selected = null)
    {
        $output = null;
        $optionElement = new Element();
        $optionElement->init('option');
        /* handle selected */
        if (is_string($selected)) {
            $selected = array_filter(explode(', ', $selected));
        }
        /* process options */
        foreach ($optionArray as $key => $value) {
            if ($key || $value) {
                $output .= $optionElement->copy()->attr(['selected' => $value === $selected || in_array($value, $selected) ? 'selected' : null, 'value' => $value])->text(is_string($key) ? $key : $value);
            }
        }
        return $output;
    }