PHP 8.4.1 Released!

Random\Randomizer::shuffleArray

(PHP 8 >= 8.2.0)

Random\Randomizer::shuffleArrayGet a permutation of an array

DescripciΓ³n

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.

ParΓ‘metros

array

The array whose values are shuffled.

The input array will not be modified.

Valores devueltos

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

Errores/Excepciones

Ejemplos

Ejemplo #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";
?>

El resultado del ejemplo serΓ­a algo similar a:

Salad: 🍎, πŸ₯, πŸ‡, 🍌, πŸ‘
Another Salad: πŸ‘, πŸ‡, πŸ₯, 🍎, 🍌
οΌ‹add a note

User Contributed Notes

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