Jump to content

[SOLVED] random array


zipp

Recommended Posts

Hello, Im trying to make a script that randomly generates 4 numbers from an array, without duplicates.  I have the random generation done, but i cant figure out how to get rid of duplicates.

 

Here is what I have so far:

 

<?php
$quote = array(
1  => "abc",
2  => "def",
3  => "hij",
4  => "klm",
5  => "nop",
6  => "qrs",
7  => "tuv",
8  => "wxyz",
);

$i = 1;
while ($i <= 4) {
$randnum = rand(1,7); 
echo"$quote[$randnum] <br />";
$i++;
}


?>

Link to comment
https://forums.phpfreaks.com/topic/61414-solved-random-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.