Random\Randomizer::shuffleArray
(PHP 8 >= 8.2.0)
Random\Randomizer::shuffleArray — Get a permutation of an array
Description
Returns a uniformly selected permutation of the input array.
Each possible permutation of the input array is equally likely to be returned.
Return Values
A permutation of the values of array.
Array keys of the input array will not be preserved; the returned array will be a list (array_is_list()).
Errors/Exceptions
- Any Throwables thrown by the Random\Engine::generate() method of the underlying
Random\Randomizer::$engine.
Examples
Example #1 Random\Randomizer::shuffleArray() example
<?php
$r = new \Random\Randomizer();
$fruits = [ 'red' => '๐', 'green' => '๐ฅ', 'yellow' => '๐', 'pink' => '๐', 'purple' => '๐' ];
// Shuffle array:
echo "Salad: ", implode(', ', $r->shuffleArray($fruits)), "\n";
// Shuffle again:
echo "Another Salad: ", implode(', ', $r->shuffleArray($fruits)), "\n";
?>The above example will output something similar to:
Salad: ๐, ๐ฅ, ๐, ๐, ๐ Another Salad: ๐, ๐, ๐ฅ, ๐, ๐
โ and โ to navigate โข Enter to select โข Esc to close โข / to open