note 96282 added to function.shuffle

From: Date: Thu, 18 Feb 2010 14:51:50 +0000
Subject: note 96282 added to function.shuffle
Groups: php.notes 
Request: Send a blank email to php-notes+get-166149@lists.php.net to get a copy of this message
an extension of some previous notes to shuffle two-dimensional arrays: -preserves main arrays keys -shuffles every internal array the same <?php function array_multishuffle($array = array()){ $key = key($array); $count = count($array[$key]); $keys = range(0,$count-1); shuffle($keys); $new_array = array(); while($sub_array = current($array)){ $name = key($array); foreach($keys as $key){ $new_array[$name][] = $sub_array[$key]; } next($array); } return $new_array; } $array = array( 'id'=>array(10,20,30,40), 'name'=>array('bob','sam','ken','hermenegildo') ); print_r(array_multishuffle($array)); /* Array ( [id] => Array ( [0] => 20 [1] => 40 [2] => 10 [3] => 30 ) [name] => Array ( [0] => sam [1] => hermenegildo [2] => bob [3] => ken ) )*/ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 124.210.231.207 ---- Manual Page -- http://www.php.net/manual/en/function.shuffle.php Edit -- https://master.php.net/note/edit/96282 Del: integrated -- https://master.php.net/note/delete/96282/integrated Del: useless -- https://master.php.net/note/delete/96282/useless Del: bad code -- https://master.php.net/note/delete/96282/bad+code Del: spam -- https://master.php.net/note/delete/96282/spam Del: non-english -- https://master.php.net/note/delete/96282/non-english Del: in docs -- https://master.php.net/note/delete/96282/in+docs Del: other reasons-- https://master.php.net/note/delete/96282 Reject -- https://master.php.net/note/reject/96282 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166149) next »