note 25956 added to function.shuffle

From: Date: Sat, 12 Oct 2002 20:31:59 +0000
Subject: note 25956 added to function.shuffle
Groups: php.notes 
Request: Send a blank email to php-notes+get-37983@lists.php.net to get a copy of this message
Here is a quick and dirty way to shuffle associative arrays and not loose the key value relationship : function assc_shuffle($orig_array) { for($i=0;$i < count($orig_array);$i++) { $map[] = $i; } shuffle($map); foreach($map as $mk=>$mv) { $wait=0; foreach($orig_array as $ok=>$ov) { if ($mv == $wait) { $proc_array[$ok] = $ov; break; } $wait++; } } return $proc_array; } Hope this help someone out. Dan Morgan -- http://www.php.net/manual/en/function.shuffle.php http://master.php.net/manage/user-notes.php?action=edit+25956 http://master.php.net/manage/user-notes.php?action=delete+25956 http://master.php.net/manage/user-notes.php?action=reject+25956

« previous php.notes (#37983) next »