Menu Home

shuffle

osbo.com | PHP | Functions | shuffle

Shuffle an array

Syntax

shuffle ( array &$array ) : bool

Parameters

array

The array.

Return

Returns TRUE on success or FALSE on failure.

Examples

array

<?

$array = range(1, 20);

shuffle($array);

print_r($array);

?>
Array
(
    [0] => 2
    [1] => 15
    [2] => 13
    [3] => 18
    [4] => 9
    [5] => 4
    [6] => 3
    [7] => 7
    [8] => 14
    [9] => 11
    [10] => 8
    [11] => 5
    [12] => 6
    [13] => 1
    [14] => 16
    [15] => 17
    [16] => 20
    [17] => 19
    [18] => 12
    [19] => 10
)

Return

<?

$array = range(1, 20);

$return = shuffle($array);

var_export($return);

?>
true

PHP