You are here

private function MultichoiceQuestion::shuffle in Quiz 8.6

Same name and namespace in other branches
  1. 8.5 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceQuestion::shuffle()
  2. 6.x question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceQuestion::shuffle()

Custom shuffle function.

It keeps the array key - value relationship intact.

Parameters

array $array:

Return value

array

2 calls to MultichoiceQuestion::shuffle()
MultichoiceQuestion::getAnsweringForm in question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php
Get the form through which the user will answer the question.
MultichoiceQuestion::getNodeView in question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php
Implementation of getNodeView().

File

question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php, line 475

Class

MultichoiceQuestion
@QuizQuestion ( id = "multichoice", label = Plugin annotation @Translation("Multiple choice question"), handlers = { "response" = "\Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse" } )

Namespace

Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion

Code

private function shuffle(array &$array) {
  $newArray = array();
  $toReturn = array_keys($array);
  shuffle($toReturn);
  foreach ($toReturn as $key) {
    $newArray[$key] = $array[$key];
  }
  $array = $newArray;
  return $toReturn;
}