The php Function ArrayRand
There are many reasons why you may want to use random keys to select values from an associative array. For example, you might want to reorder the items in the array, or perhaps you need to select an element from the same key more than once (in order to display that item). Unfortunately, the shuffle() function mangles the keys of your array, so you would have to use another method, such as array_rand().
The php function array_rand allows you to randomly pick a key or a set of keys from an associative array and return them. This is a great way to select values that you cannot easily get with the shuffle() function because it leaves the original array intact.
array_rand() takes in two parameters: $array and $num. $array stores the key-value pairs in the array and $num holds how many elements you need to fetch from the array. By default this is one.
Then, if you have specified how many entries you want to select, array_rand() returns the key for each of the random entries. Otherwise, it will return an array of keys for each of the random entries. In either case, attempting to pick more than the number of elements in the array will result in an E_WARNING level error. This is because attempting to pull from the same key twice will overwrite the value with a new one, rather than picking a random value. This is due to a bug in PHP which will be fixed at some point in the future.