note 67432 deleted from function.shuffle by cmb

From: Date: Mon, 22 Nov 2021 17:21:47 +0000
Subject: note 67432 deleted from function.shuffle by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217280@lists.php.net to get a copy of this message
Note Submitter: ---- 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 } ?>

« previous php.notes (#217280) next »