src/Constraints/IsSelected.php
protected function getSelectedValueFromSelect(Crawler $select)
    {
        $selected = [];

        foreach ($select->children() as $option) {
            if ($option->nodeName === 'optgroup') {
                foreach ($option->childNodes as $child) {
                    if ($child->hasAttribute('selected')) {
                        $selected[] = $this->getOptionValue($child);
                    }
                }
            } elseif ($option->hasAttribute('selected')) {
                $selected[] = $this->getOptionValue($option);
            }
        }

        return $selected;
    }
protected function getSelectedValueFromSelect(Crawler $select)
    {
        $selected = [];

        foreach ($select->children() as $option) {
            if ($option->nodeName === 'optgroup') {
                foreach ($option->childNodes as $child) {
                    if ($child->hasAttribute('selected')) {
                        $selected[] = $this->getOptionValue($child);
                    }
                }
            } elseif ($option->hasAttribute('selected')) {
                $selected[] = $this->getOptionValue($option);
            }
        }

        return $selected;
    }
protected function getSelectedValueFromSelect ( Crawler $ select ) { $ selected = [ ] ; foreach ( $ select -> children ( ) as $ option ) { if ( $ option -> nodeName === 'optgroup' ) { foreach ( $ option -> childNodes as $ child ) { if ( $ child -> hasAttribute ( 'selected' ) ) { $ selected [ ] = $ this -> getOptionValue ( $ child ) ; } } } elseif ( $ option -> hasAttribute ( 'selected' ) ) { $ selected [ ] = $ this -> getOptionValue ( $ option ) ; } } return $ selected ; }
Get the selected value from a select field.

@param  \Symfony\Component\DomCrawler\Crawler  $select
@return array
Get the selected value from a select field .