lithium\template\helper\Form::_selectOptions PHP Method

_selectOptions() protected method

Generally, this method should not need to be called directly, but through select().
protected _selectOptions ( array $list, array $scope ) : string
$list array Either a flat key/value array of select menu options, or an array which contains key/value elements and/or elements where the keys are `` titles and the values are sub-arrays of key/value pairs representing nested `
$scope array An array of options passed to the parent scope, including the currently selected value of the associated form element.
return string Returns a string of `` tags to be embedded in a select element.
    protected function _selectOptions(array $list, array $scope)
    {
        $result = "";
        foreach ($list as $value => $title) {
            if (is_array($title)) {
                $label = $value;
                $options = array();
                $raw = $this->_selectOptions($title, $scope);
                $params = compact('label', 'options', 'raw');
                $result .= $this->_render('select', 'option-group', $params);
                continue;
            }
            $selected = is_array($scope['value']) && in_array($value, $scope['value']) || $scope['empty'] && empty($scope['value']) && $value === '' || is_scalar($scope['value']) && (string) $scope['value'] === (string) $value;
            $options = $selected ? array('selected' => true) : array();
            $params = compact('value', 'title', 'options');
            $result .= $this->_render('select', 'select-option', $params);
        }
        return $result;
    }