Re: multiple random items

From: Date: Mon, 16 Jul 2007 14:49:40 +0000
Subject: Re: multiple random items
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-258925@lists.php.net to get a copy of this message
On Mon, 2007-07-16 at 15:40 +0100, chris@aquanuke.com wrote: > Hi I have this script which pulls 1 random item from a txt file. > How would I modify it to pull 10 random items. > > <?php > $delim = "\n"; > $quotefile = "names.txt"; > $fp = fopen($quotefile, "r"); > $contents = fread($fp, filesize($quotefile)); > $quote_arr = explode($delim,$contents); > fclose($fp); $herequotes = array(); for( $i = 0; $i < 10; $i++ ) { > // generate random quote index > $quote_index = (mt_rand(1, sizeof($quote_arr)) - 1); > // get quote at $quote_index and return it > $herequote = $quote_arr[$quote_index]; $herequotes[] = $herequote; } > echo "<li><a > href='http://www.$herequote'>$herequote</a></li>"; > ?> > > Thanks You're welcome. Cheers, Rob. -- ........................................................... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ...........................................................

« previous php.general (#258925) next »