You are here

private function MatchingQuestion::customShuffle in Quiz 8.4

Shuffles an array, but keeps the keys, and makes sure the first element is the default element

Parameters

$array: Array to be shuffled

Return value

A shuffled version of the array with $array['def'] = '' as the first element

1 call to MatchingQuestion::customShuffle()
MatchingQuestion::getAnsweringForm in question_types/matching/lib/Drupal/matching/MatchingQuestion.php
Implementation of getAnsweringForm

File

question_types/matching/lib/Drupal/matching/MatchingQuestion.php, line 257
The main classes for the matching question type.

Class

MatchingQuestion
Extension of QuizQuestion.

Namespace

Drupal\matching

Code

private function customShuffle(array $array = array()) {
  $new_array = array();
  $new_array['def'] = '';
  while (count($array)) {
    $element = array_rand($array);
    $new_array[$element] = $array[$element];
    unset($array[$element]);
  }
  return $new_array;
}