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.