| Viewed 159 times

php how to shuffle array


php how to shuffle array

1 Answer
Mohammad Qandeel
Answered
5

shuffle() is a function in PHP. it can randomly mix array values each time it is called
shuffle() function Returns logical values (true,false)

Example

<?php
    echo'<pre>';
    $array    = [1,2,3,4,5,6,7,8,9]; 
    shuffle($array);
    print_r($array);
    echo'</pre>';
?>

the output will be Different result each time

Array
(
    [0] => 1
    [1] => 7
    [2] => 4
    [3] => 8
    [4] => 2
    [5] => 6
    [6] => 9
    [7] => 5
    [8] => 3
)

Array
(
    [0] => 5
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 9
    [5] => 8
    [6] => 6
    [7] => 1
    [8] => 7
)
// etc