Re: randomly picking a variable from an array

From: Date: Fri, 07 Sep 2001 19:41:47 +0000
Subject: Re: randomly picking a variable from an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66457@lists.php.net to get a copy of this message
Example if you do know the number of items in the array: /* Begin */ $choice = rand(1, 6); echo $array[$choice]; /* End */ That will randomly pick something from 1-6 in the array. If you do not know the number of things in the array (say it is off a form or something): /* Begin */ $numinarray = count($array); $choice = rand(1, $numinarray); echo $array[$choice]; /* End */ HTH! - k ----- Original Message ----- From: "Joseph Bannon" <JBannon@advparadigm.com> To: "PHP (E-mail)" <php-general@lists.php.net> Sent: Friday, September 07, 2001 3:08 PM Subject: [PHP] randomly picking a variable from an array > How do you randomly picking a variable from an array with PHP? > > Thanks, > > Joseph > > > > > PS. Thanks to those who helped me with GD. If you go to my site, you'll see > the new counter I created at the top of the page. > > http://www.collegesucks.com > > > > > > > > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#66457) next »