note 67974 added to function.array-rand

From: Date: Fri, 07 Jul 2006 20:28:28 +0000
Subject: note 67974 added to function.array-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-114582@lists.php.net to get a copy of this message
Well, I came up with a workaround for my earlier problem. For those of you who might need to shuffle around multi-dimensional arrays (I used this to randomize a list of headlines from a MySQL database query), here's what I did to get the desired output: $subs = //my query went here $shfl = array_rand($subs, 5); $shsubs = array(); for ($x=0; $x<count($shfl); $x++) { $shsubs[] = $subs[$shfl[$x]]; } There may in fact be a much easier way to do this, but this is what I came up with and its working! Thanks to everyone that makes php.net the invaluable tool for us nooobies! ---- Server IP: 216.194.113.175 Probable Submitter: 66.67.226.83 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.array-rand.php Edit -- http://master.php.net/note/edit/67974 Del: integrated -- http://master.php.net/note/delete/67974/integrated Del: useless -- http://master.php.net/note/delete/67974/useless Del: bad code -- http://master.php.net/note/delete/67974/bad+code Del: spam -- http://master.php.net/note/delete/67974/spam Del: non-english -- http://master.php.net/note/delete/67974/non-english Del: in docs -- http://master.php.net/note/delete/67974/in+docs Del: other reasons-- http://master.php.net/note/delete/67974 Reject -- http://master.php.net/note/reject/67974 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114582) next »