note 33460 added to function.shuffle
| From: | jennifer at withoutabox dot com | Date: | Thu, 26 Jun 2003 17:16:56 +0000 |
| Subject: | note 33460 added to function.shuffle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51051@lists.php.net to get a copy of this message | ||
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;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----
Manual Page -- http://www.php.net/manual/en/function.shuffle.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33460
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33460&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33460&report=yes