public static function setOptions(HTMLFactoryInterface $factory, HTMLElement $select, $options = [], $checkedValue = null)
    {
        foreach ($options as $value => $title) {
            // Build option
            $option = $factory->buildHtmlElement('option', $title);
            $option->attr('value', $value);

            // Append option to container
            $factory->getHTMLHandler()->append($select, $option);
        }

        // Set checked values
        $checkedValues = is_array($checkedValue) ? $checkedValue : [$checkedValue];
        foreach ($checkedValues as $value) {
            $option = $select->select(sprintf('option[value=%s]', $value))->item(0);
            if ($option) {
                $factory->getHTMLHandler()->attr($option, 'selected', 'selected');
            }
        }
    }
public static function setOptions(HTMLFactoryInterface $factory, HTMLElement $select, $options = [], $checkedValue = null)
    {
        foreach ($options as $value => $title) {
            // Build option
            $option = $factory->buildHtmlElement('option', $title);
            $option->attr('value', $value);

            // Append option to container
            $factory->getHTMLHandler()->append($select, $option);
        }

        // Set checked values
        $checkedValues = is_array($checkedValue) ? $checkedValue : [$checkedValue];
        foreach ($checkedValues as $value) {
            $option = $select->select(sprintf('option[value=%s]', $value))->item(0);
            if ($option) {
                $factory->getHTMLHandler()->attr($option, 'selected', 'selected');
            }
        }
    }
public static function setOptions ( HTMLFactoryInterface $ factory , HTMLElement $ select , $ options = [ ] , $ checkedValue = null ) { foreach ( $ options as $ value => $ title ) { // Build option $ option = $ factory -> buildHtmlElement ( 'option' , $ title ) ; $ option -> attr ( 'value' , $ value ) ; // Append option to container $ factory -> getHTMLHandler ( ) -> append ( $ select , $ option ) ; } // Set checked values $ checkedValues = is_array ( $ checkedValue ) ? $ checkedValue : [ $ checkedValue ] ; foreach ( $ checkedValues as $ value ) { $ option = $ select -> select ( sprintf ( 'option[value=%s]' , $ value ) ) -> item ( 0 ) ; if ( $ option ) { $ factory -> getHTMLHandler ( ) -> attr ( $ option , 'selected' , 'selected' ) ; } } }
Sets the given array as options in select.

For example:
If we are given an array the keys of the array will be the options values
and the key values will be the options titles.

@param HTMLFactoryInterface $factory
@param HTMLElement          $select
@param array                $options
@param mixed|array          $checkedValue

@throws \InvalidArgumentException
@throws \Exception
Sets the given array as options in select .