LLMS_Question::get_correct_choice()

Retrieve correct choices for a given question


Return Return

(array)


Top ↑

Source Source

File: includes/models/model.llms.question.php

	public function get_correct_choice() {

		$correct = false;

		if ( $this->supports( 'choices' ) && $this->supports( 'grading', 'auto' ) ) {

			$multi   = ( 'yes' === $this->get( 'multi_choices' ) );
			$correct = array();

			foreach ( $this->get_choices() as $choice ) {

				if ( $choice->is_correct() ) {
					$correct[] = $choice->get( 'id' );
					if ( ! $multi ) {
						break;
					}
				}
			}

			// Always sort multi choices for easy auto comparison.
			if ( $multi && $this->supports( 'selectable' ) ) {
				sort( $correct );
			}
		}

		return $correct;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.