Hi,
Wednesday, September 11, 2002, 12:22:05 AM, you wrote:
RM> Could someone show me a quick and simple way to randomly sort array
RM> elements? I can't seem to pinpoint the correct parameters in the docs.
RM> Thanks!
The function you need I think is shuffle()
--
regards,
Tom
--
PHP Gene
Thanks all for you submissions. This is what I came up with, where
$this_key is a random selection from the array $the_exploded_ids. I
don't know why, but, array_rand() won't work with selection quanity
parameter of less than 2. Anybody know why?
srand ((float) microtime() * 1000);
$input
This appears to work
// Normal array
$a1 = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
srand((float) microtime() * 1000);
$a_temp = array_rand($a1, sizeof($a1));
// Random array
while (list(, $value) = each($a_temp)) {
$a2[] = $a1[$value];
}
print_r($a2);
- jacob
At 22:22 09/10/2002,
nal Message-
> From: David Rice [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 10:49 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] random array sort
>
>
> But if array_rand() truly pulls out random keys, how do you guarantee
> that you are not rando
into another array.
>
> -Mike
>
>
>
>> -Original Message-
>> From: ROBERT MCPEAK [mailto:[EMAIL PROTECTED]]
>> Sent: Tuesday, September 10, 2002 10:22 AM
>> To: [EMAIL PROTECTED]
>> Subject: [PHP] random array sort
>>
>>
>> Could so
You could use array_rand() to take stuff out of the array at random and then
stuff it all back into another array.
-Mike
> -Original Message-
> From: ROBERT MCPEAK [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 10:22 AM
> To: [EMAIL PROTECTED]
> Subjec
Could someone show me a quick and simple way to randomly sort array
elements? I can't seem to pinpoint the correct parameters in the docs.
Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
7 matches
Mail list logo