Entry
How can I select 3 different random elements from a single dimension array using rand?
Feb 3rd, 2001 00:04
Philip Olson, Dave Martindale, http://www.php.net/manual/en/function.array-rand.php
The "best" (easiest) way to do this would be to use array_rand, this
can be done as such :
<?php
$array = array('a','b','c','d','e','f','g','h','i','j','k','l');
srand ((double) microtime() * 1000000);
$key = array_rand($array,3);
$array[$key[0]];
$array[$key[1]];
$array[$key[2]];
?>
See :
http://www.php.net/manual/en/function.array-rand.php