note 9117 added to array_flip
| From: | rupert at complinet dot com | Date: | Tue, 17 Oct 2000 14:08:31 +0000 |
| Subject: | note 9117 added to array_flip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-6571@lists.php.net to get a copy of this message | ||
if you're a bit more of a purist about your random values, try the following algortithm. note:
for reasons that should be obvious, this is only useful if you're using the array like a stack
or a queue (ie; it's indexed, and the actual value of the indices don't matter), but for
me this seems to be most of the time.
<?
mt_srand((double)microtime()*1000000);
$bob=array_flip($bob);
while (list($key,$val)=each($bob)) {
$bob[$key]=mt_rand();
}
$bob=array_flip($bob); #we now have an array with highly random indices
ksort($bob);
?>
http://www.php.net/manual/function.array-flip.php