note 17952 added to function.mt-rand
| From: | php-general at lists dot php dot net | Date: | Fri, 04 Jan 2002 18:24:59 +0000 |
| Subject: | note 17952 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-24399@lists.php.net to get a copy of this message | ||
Just to add to what jamesmc submitted.
<?
$a = array("item 1","item 2","item
3","item 4","item 5","item 6","item
7","item 8");
mt_srand ((float) microtime() *
1000000);
# Replace the below line
# $r = mt_rand(0,7);
# with
$r = mt_rand(0, sizeof($a));
print"Random Value for today is: $a[$r]";
?>
At least this way, you never have to know the length of an array.
Big Din K.R.
massimo@gamebox.net
--
http://www.php.net/manual/en/function.mt-rand.php
http://master.php.net/manage/user-notes.php?action=edit+17952
http://master.php.net/manage/user-notes.php?action=delete+17952
http://master.php.net/manage/user-notes.php?action=reject+17952