Ahh! Array!!

From: Date: Wed, 02 Aug 2000 18:31:47 +0000
Subject: Ahh! Array!!
Groups: php.general 
Request: Send a blank email to php-general+get-9776@lists.php.net to get a copy of this message
This is driving me nuts!!!!!! It should be SO simple and for some reason my brain isn't working!!!! I'm selecting records from a database. $num is the number of rows. I just want to get an array of 6 random numbers, without getting the same number in the array twice. This is in php3. I've tried a million variations of this and can't get it to work. Please help!!! $i=0; $id[] = ""; while($i < 6) { $pick = rand(0,$num); for($j=0; $j <= count($id); $j++) { if($j > 0 && $id[$j] == $pick) { $in_set = 1; break; } else { $id[] .= $pick; $list .= $pick."<BR>"; $in_set = 0; } } if($in_set == 0) { $i++; } else { $i = $i; } } That's it...Thanks, Joe

« previous php.general (#9776) next »