public static function WebformArrayHelper::shuffle in Webform 8.5
Same name and namespace in other branches
- 6.x src/Utility/WebformArrayHelper.php \Drupal\webform\Utility\WebformArrayHelper::shuffle()
Shuffle an associative array while maintaining keys.
Parameters
array $array: An associative array.
Return value
array The associative array with it key/value pairs randomized.
See also
http://stackoverflow.com/questions/4102777/php-random-shuffle-array-main...
1 call to WebformArrayHelper::shuffle()
- WebformElementHelper::randomize in src/
Utility/ WebformElementHelper.php - Randomoize an associative array of element values and disable page caching.
File
- src/
Utility/ WebformArrayHelper.php, line 227
Class
- WebformArrayHelper
- Provides helper to operate on arrays.
Namespace
Drupal\webform\UtilityCode
public static function shuffle(array $array) {
$keys = array_keys($array);
shuffle($keys);
$random = [];
foreach ($keys as $key) {
$random[$key] = $array[$key];
}
return $random;
}