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
It works perfect. print_r(shuffle($slides))) gives the output of TRUE, since the return value of shuffle
is a boolean and not an array.
See the working example here: http://codepad.org/B5SlcjGf
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.
i am not sure how you want it to display but you can loop the array and use php rand(0,arraylen) function to parse the array.
Instead of
print_r(shuffle($slides));
do
shuffle($slides);
print_r($slides);
You see shuffle() shuffles the array in-place