multi dimensional array in random order

后端 未结 4 1622
谎友^
谎友^ 2020-12-02 01:43

I want to make it so that my multi dimensional array is in a random order. How would you do it?

// This is how the array looks like
print_r($slides);

Array
         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 02:27

    shuffle() is the way to go here. It prints 1 because shuffle changes the array in-place and returns a boolean, as it is written in the documentation:

    Returns TRUE on success or FALSE on failure.

    I suggest to also read the documentation of array_rand():

    Picks one or more random entries out of an array, and returns the key (or keys) of the random entries.


    Always read documentation if you use built-in functions. Don't just assume how the work. I bet it took more time to write the question than looking this up.

提交回复
热议问题