note 86949 added to function.shuffle
| From: | tony at brokerbin dot com | Date: | Wed, 12 Nov 2008 03:26:06 +0000 |
| Subject: | note 86949 added to function.shuffle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146408@lists.php.net to get a copy of this message | ||
Here is IMO the simplest and extremely fast way to shuffle an associative array AND keep the
key=>value relationship. However, it ONLY works if there are NO NUMERIC keys AT ALL. Look into
array_merge for the reason why.
<?php
$unshuffled = array('one'=>1,'two'=>2,'three'=>3);
$shuffled = array_merge( array_flip(array_rand($unshuffled,count($unshuffled))),$unshuffled );
?>
peace
----
Server IP: 208.69.120.35
Probable Submitter: 66.173.76.218
----
Manual Page -- http://www.php.net/manual/en/function.shuffle.php
Edit -- https://master.php.net/note/edit/86949
Del: integrated -- https://master.php.net/note/delete/86949/integrated
Del: useless -- https://master.php.net/note/delete/86949/useless
Del: bad code -- https://master.php.net/note/delete/86949/bad+code
Del: spam -- https://master.php.net/note/delete/86949/spam
Del: non-english -- https://master.php.net/note/delete/86949/non-english
Del: in docs -- https://master.php.net/note/delete/86949/in+docs
Del: other reasons-- https://master.php.net/note/delete/86949
Reject -- https://master.php.net/note/reject/86949
Search -- https://master.php.net/manage/user-notes.php