function shuffleArray(&$array) { //Create and init tem array $tempQuantity = count($array); $tempArr = array(); for ($i = 0; $i < $tempQuantity; $i++) { $tempArr[$i] = FALSE; } //Shuffle input array for ($i = 1; $i <= $tempQuantity; $i++) { while (TRUE) { $temp = mt_rand(0, $tempQuantity - 1); if (!$tempArr[$temp]) { //if FALSE $tempArr[$temp] = $array[$i]; break; } } } //Return result via link $array = $tempArr; } //MAIN LOOP arrayInit($Arr, $quantity); displayArray($Arr); shuffleArray($Arr); displayArray($Arr); // Output execution time for script $time = microtime(TRUE) - $start; echo "<br />" . "<br />"; printf('Script are executed %.8F sec.', $time);
function getOptionsOrderRandomPreserveGroups($variable, $groups = array()) { global $engine; //echo 'ohno'; $var = $engine->getVariableDescriptive($variable); $options = $engine->getFill($variable, $var, SETTING_OPTIONS); $order = array(); $groups = shuffleArray($groups); $cnt = 1; foreach ($groups as $group) { $gr = explode(",", $group); foreach ($gr as $g) { $order[$cnt] = $g; $cnt++; } } return $order; }