llms_shuffle_choices( array $choices )

Shuffles choices until the choice order has changed from the original.


Description Description

The smaller the list of choices the greater the chance of shuffling not changing the array.


Top ↑

Parameters Parameters

$choices

(array) (Required) Choices from an LLMS_Question


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/functions/llms.functions.quiz.php

function llms_shuffle_choices( $choices ) {

	$count = count( $choices );

	// If we only have one choice there's not much to shuffle with.
	if ( $count <= 1 ) {
		return $choices;

		// Reverse the array when we only have two.
	} elseif ( 2 === $count ) {
		$shuffled = array_reverse( $choices );

		// Shuffle until the order has changed.
	} else {

		$shuffled = $choices;

		while ( $shuffled === $choices ) {
			shuffle( $shuffled );
		}
	}

	return $shuffled;

}

Top ↑

Changelog Changelog

Changelog
Version Description
3.16.12 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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