note 26902 deleted from function.array-rand by sniper
| From: | sniper@php.net | Date: | Fri, 06 Jun 2003 19:49:09 +0000 |
| Subject: | note 26902 deleted from function.array-rand by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-49909@lists.php.net to get a copy of this message | ||
Note Submitter: seaATuniversalmetropolis.com
----
Posting this again, don't know where the original wound up -
A much simpler way to pick a random entry out of an array.
// place your required values in an array
$colours =
array("green","red","orange","blue","peach");
// pick a random value from the array (minus one because your range in the array starts at 0 rather
than 1)
$colours = $colours[rand(0,count($colours)-1)];
// verify
print $colours;
Remember to seed the random generator with srand() at the beginning of your script.