protected function flatten_options($options, $nothing) {
        $flattened = [];

        foreach ($options as $value => $option) {
            if (is_array($option)) {
                foreach ($option as $groupname => $optoptions) {
                    if (!isset($flattened[$groupname])) {
                        $flattened[$groupname] = [
                            'name' => $groupname,
                            'isgroup' => true,
                            'options' => []
                        ];
                    }
                    foreach ($optoptions as $optvalue => $optoption) {
                        $cleanedvalue = $this->clean_url($optvalue);
                        $flattened[$groupname]['options'][$cleanedvalue] = [
                            'name' => $optoption,
                            'value' => $cleanedvalue,
                            'selected' => $this->selected == $optvalue,
                        ];
                    }
                }

            } else {
                $cleanedvalue = $this->clean_url($value);
                $flattened[$cleanedvalue] = [
                    'name' => $option,
                    'value' => $cleanedvalue,
                    'selected' => $this->selected == $value,
                ];
            }
        }

        if (!empty($nothing)) {
            $value = key($nothing);
            $name = reset($nothing);
            $flattened = [
                $value => ['name' => $name, 'value' => $value, 'selected' => $this->selected == $value]
            ] + $flattened;
        }

        // Make non-associative array.
        foreach ($flattened as $key => $value) {
            if (!empty($value['options'])) {
                $flattened[$key]['options'] = array_values($value['options']);
            }
        }
        $flattened = array_values($flattened);

        return $flattened;
    }