You are here

function multichoice_get_number_of_corrects in Quiz 6.3

Same name and namespace in other branches
  1. 5.2 multichoice.module \multichoice_get_number_of_corrects()
  2. 6.6 question_types/multichoice/multichoice.module \multichoice_get_number_of_corrects()
  3. 6.2 multichoice.module \multichoice_get_number_of_corrects()
  4. 6.5 question_types/multichoice/multichoice.module \multichoice_get_number_of_corrects()

Get the number of correct answers in an array of multichoice answers.

Parameters

$answers: Array of multichoice answers.

Return value

$corrects The number of correct answers found in that array. Returns 0 if none found.

2 calls to multichoice_get_number_of_corrects()
multichoice_insert in question_types/multichoice/multichoice.module
Implementation of hook_insert().
multichoice_update in question_types/multichoice/multichoice.module
Implementation of hook_update().

File

question_types/multichoice/multichoice.module, line 513
Multiple choice question type for the Quiz module.

Code

function multichoice_get_number_of_corrects($answers) {
  $corrects = 0;
  if (is_array($answers)) {
    foreach ($answers as $answer) {

      // We have to filter this because personality questions don't
      // actually *set* $answer['correct']. Doing a += on a NULL will
      // generate an E_NOTICE.
      if (!empty($answer['correct'])) {
        $corrects += $answer['correct'];
      }
    }
  }
  return $corrects;
}