note 33460 deleted from function.shuffle by aidan
| From: | aidan@php.net | Date: | Thu, 26 Aug 2004 22:33:59 +0000 |
| Subject: | note 33460 deleted from function.shuffle by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75368@lists.php.net to get a copy of this message | ||
Note Submitter: jennifer at withoutabox dot com
----
This snippet worked for me (based on drmccolgan's). It keeps the integrity of the
key=>value relationship and provided a good shuffle.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
srand ((double) microtime() * 10000000);
for($i=0;$i < count($array);$i++) {
$map[] = $i;
}
shuffle($map);
foreach($map as $mk=>$mv) {
$wait=0;
foreach($array as $ok=>$ov) {
if ($mv == $wait) {
$proc_array[$ok] = $ov;
break;
}
$wait++;
}
}
$array=$proc_array;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~