Random\Randomizer::shuffleArray

(PHP 8 >= 8.2.0)

Random\Randomizer::shuffleArrayGet a permutation of an array

Beschreibung

public Random\Randomizer::shuffleArray(array $array): array

Returns a uniformly selected permutation of the input array.

Each possible permutation of the input array is equally likely to be returned.

Parameter-Liste

array

The Array whose values are shuffled.

The input Array will not be modified.

Rรผckgabewerte

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()).

Fehler/Exceptions

Beispiele

Beispiel #1 Random\Randomizer::shuffleArray() example

<?php
$r
= new \Random\Randomizer();

$fruits = [ 'red' => '๐ŸŽ', 'green' => '๐Ÿฅ', 'yellow' => '๐ŸŒ', 'pink' => '๐Ÿ‘', 'purple' => '๐Ÿ‡' ];

// Shuffle array:
echo "Salad: ", join( ', ', $r->shuffleArray( $fruits ) ), "\n";

// Shuffle again:
echo "Another Salad: ", join( ', ', $r->shuffleArray( $fruits ) ), "\n";
?>

Das oben gezeigte Beispiel erzeugt eine รคhnliche Ausgabe wie:

Salad: ๐ŸŽ, ๐Ÿฅ, ๐Ÿ‡, ๐ŸŒ, ๐Ÿ‘
Another Salad: ๐Ÿ‘, ๐Ÿ‡, ๐Ÿฅ, ๐ŸŽ, ๐ŸŒ
๏ผ‹add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top