note 9117 modified in array_flip by ronabop
| From: | ronabop@php.net | Date: | Wed, 18 Oct 2000 04:25:06 +0000 |
| Subject: | note 9117 modified in array_flip by ronabop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-6616@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