note 67432 added to function.shuffle

From: Date: Wed, 07 Jun 2006 21:53:04 +0000
Subject: note 67432 added to function.shuffle
Groups: php.notes 
Request: Send a blank email to php-notes+get-113679@lists.php.net to get a copy of this message
Posted below is code that you would expect to work <?php $keys = shuffle(array_keys($arr)); foreach ($keys as $key) { $arr_elem = $arr[$key]; // do what you want with the array element } ?> This in fact does not work because shuffle returns a boolean true or false. More accurate code using this method would be: <?php $keys = array_keys($arr); shuffle($keys); foreach ($keys as $key) { $arr_elem = $arr[$key]; // do what you want with the array element } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 69.1.58.20 ---- 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.shuffle.php Edit -- http://master.php.net/note/edit/67432 Del: integrated -- http://master.php.net/note/delete/67432/integrated Del: useless -- http://master.php.net/note/delete/67432/useless Del: bad code -- http://master.php.net/note/delete/67432/bad+code Del: spam -- http://master.php.net/note/delete/67432/spam Del: non-english -- http://master.php.net/note/delete/67432/non-english Del: in docs -- http://master.php.net/note/delete/67432/in+docs Del: other reasons-- http://master.php.net/note/delete/67432 Reject -- http://master.php.net/note/reject/67432 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#113679) next »