> -----Original Message-----
> From: Deirdre Mc Cann [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, September 10, 2001 6:30 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Unique Array
> 
> 
> Can anyone help me? I need to produce a random and uniques 
> array using numbers between 0 and 9. I tried to create a
> random array and them make it unique.
> 
> for ($i = 0; $i<100; $i++){
>       $a[$i] = rand(0,9);
>       $test=$a[$i];
>       }
> 
> $ra = array_unique($test);
> 
> I keep getting an error saying $test is the incorrect type. 

Because you've set $test equal to one element of $a (making it an
integer).  Array_unique() wants to operate on an entire array.

What I'd do, assuming I'm understanding the question correctly, would be
something more like:

        $a = range(0,9);
        srand((double)microtime()*1000000);
        shuffle($a);

(That is, get all your values loaded first, then just randomly rearrange
the order.)


---
Mark Roedel             |  "Blessed is he who has learned to laugh
Systems Programmer      |   at himself, for he shall never cease
LeTourneau University   |   to be entertained."
Longview, Texas, USA    |                           -- John Powell 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to