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
But if array_rand() truly pulls out random keys, how do you guarantee
that you are not randomly pulling out the same key as you iterate
through the array?
Perhaps you could set the number of keys to return, to the size of the
array, and somehow, magically, all the keys would be included in the
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]
> Subject: [PHP] random a
6 matches
Mail list logo