private function getSelectedIndexChoices(array $answers) : array
    {
        $selectedChoices = [];

        foreach ($answers as $answer) {
            if (!ctype_digit($answer)) {
                throw new InvalidArgumentException('Answer is not an integer');
            }

            $answer = (int)$answer;

            if ($answer < 1 || $answer > count($this->choices)) {
                throw new InvalidArgumentException('Choice must be between 1 and ' . count($this->choices));
            }

            // Answers are 1-indexed
            $selectedChoices[] = $this->choices[$answer - 1];
        }

        return $selectedChoices;
    }
private function getSelectedIndexChoices(array $answers) : array
    {
        $selectedChoices = [];

        foreach ($answers as $answer) {
            if (!ctype_digit($answer)) {
                throw new InvalidArgumentException('Answer is not an integer');
            }

            $answer = (int)$answer;

            if ($answer < 1 || $answer > count($this->choices)) {
                throw new InvalidArgumentException('Choice must be between 1 and ' . count($this->choices));
            }

            // Answers are 1-indexed
            $selectedChoices[] = $this->choices[$answer - 1];
        }

        return $selectedChoices;
    }
private function getSelectedIndexChoices ( array $ answers ) : array { $ selectedChoices = [ ] ; foreach ( $ answers as $ answer ) { if ( ! ctype_digit ( $ answer ) ) { throw new InvalidArgumentException ( 'Answer is not an integer' ) ; } $ answer = ( int ) $ answer ; if ( $ answer < 1 || $ answer > count ( $ this -> choices ) ) { throw new InvalidArgumentException ( 'Choice must be between 1 and ' . count ( $ this -> choices ) ) ; } // Answers are 1-indexed $ selectedChoices [ ] = $ this -> choices [ $ answer - 1 ] ; } return $ selectedChoices ; }
Gets the list of selected indexed choices from a list of answers

@param array $answers The list of answers
@return array The list of selected choices
@throws InvalidArgumentException Thrown if the answers are not of the correct type
Gets the list of selected indexed choices from a list of answers