Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

shuffle()

Make a random permutation of the array values in place, assigning fresh zero-based keys.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

shuffle(array &$array): true

Make a random permutation of the array values in place, assigning fresh zero-based keys. The original order may recur. For a deterministic test, check the keys and multiset of values instead of expecting a particular permutation. Its generator is unsuitable for cryptographic randomness.

Signature

shuffle(array &$array): true

Example output

[true,[0,1,2],["J","Q","Q"]]

Examples

<?php
$cards = ["a"=>"Q","b"=>"J","c"=>"Q"];
$ok = shuffle($cards); $keys = array_keys($cards);
sort($cards,SORT_STRING);
echo json_encode([$ok,$keys,$cards]);

Result

[true,[0,1,2],["J","Q","Q"]]

Sources