Camroncade\Timezone\Timezone::selectForm PHP Метод

selectForm() публичный Метод

public selectForm ( null $selected = null, null $placeholder = null, array $selectAttributes = [], array $optionAttributes = [] ) : string
$selected null
$placeholder null
$selectAttributes array
$optionAttributes array
Результат string
    public function selectForm($selected = null, $placeholder = null, array $selectAttributes = [], array $optionAttributes = [])
    {
        $selectAttributesString = '';
        foreach ($selectAttributes as $key => $value) {
            $selectAttributesString = $selectAttributesString . " " . $key . "='" . $value . "'";
        }
        $optionAttributesString = '';
        foreach ($optionAttributes as $key => $value) {
            $optionAttributesString = $optionAttributesString . " " . $key . "='" . $value . "'";
        }
        $string = "<select" . $selectAttributesString . ">\n";
        if (isset($placeholder) && empty($selected)) {
            $placeholder = "<option value='' disabled selected>{$placeholder}</option>";
        } else {
            $placeholder = null;
        }
        $string = $string . $placeholder;
        foreach ($this->timezoneList as $key => $value) {
            if ($selected == $value) {
                $selectedString = "selected='" . $value . "'";
            } else {
                $selectedString = '';
            }
            $string = $string . "<option value='" . $value . "'" . $optionAttributesString . " " . $selectedString . ">" . $key . "</option>\n";
        }
        $string = $string . "</select>";
        return $string;
    }