dokuwiki\Form\OptGroup::options PHP Méthode

options() public méthode

Options can be given as associative array (value => label) or as an indexd array (label = value) or as an array of arrays. In the latter case an element has to look as follows: option-value => array ( 'label' => option-label, 'attrs' => array ( attr-key => attr-value, ... ) )
public options ( null | array $options = null )
$options null | array
    public function options($options = null)
    {
        if ($options === null) {
            return $this->options;
        }
        if (!is_array($options)) {
            throw new \InvalidArgumentException('Options have to be an array');
        }
        $this->options = array();
        foreach ($options as $key => $val) {
            if (is_int($key)) {
                $this->options[$val] = array('label' => (string) $val);
            } elseif (!is_array($val)) {
                $this->options[$key] = array('label' => (string) $val);
            } else {
                if (!key_exists('label', $val)) {
                    throw new \InvalidArgumentException('If option is given as array, it has to have a "label"-key!');
                }
                $this->options[$key] = $val;
            }
        }
        return $this;
    }