Code: Select all
$rand_keys = array_rand($spin, 2);
echo $spin[$rand_keys[0]];
echo $spin[$rand_keys[1]];Code: Select all
$rand_keys = array_rand($spin, 1);
echo $spin[$rand_keys[0]];Moderator: General Moderators
Code: Select all
$rand_keys = array_rand($spin, 2);
echo $spin[$rand_keys[0]];
echo $spin[$rand_keys[1]];Code: Select all
$rand_keys = array_rand($spin, 1);
echo $spin[$rand_keys[0]];.Return Values
If you are picking only one entry, array_rand() returns the key for a random entry. Otherwise, it returns an array of keys for the random entries. This is done so that you can pick random keys as well as values out of the array.
Code: Select all
$rand_keys = array_rand($spin, 1);
echo $spin[$rand_keys];