PHP Function Shuffle
The php function shuffle rearranges the order of the elements in an array or nested arrays. The function is very useful and can be used to create a new indexed array without the need to manually insert each element. The function also has the ability to shuffle both associative and non associative arrays. The function can also be used to randomize values or assign numeric keys starting from zero.
There is a built in function in PHP that can be used to shuffle arrays but it doesn’t do the job very well. The problem is that it tends to favour certain permutations over others, meaning the results don’t always look randomized. This problem is fixed in PHP 4.3.
Another option is to use a function called mt_rand which is an excellent random number generator that can be used to generate truly randomized numbers. The only problem with this is that it’s quite slow compared to the other options.
Another good solution is to use the Fisher Yates shuffle with an array passed by reference. This takes advantage of the improvements in PHP 7 and HHVM and produces a much more even result than the previous methods (though still not as good as an RNG that produces values purely based on the seed). This method is a bit faster than the reorder and slice method but slower than mt_rand and the shuffle and sliced approach.