note 113790 added to function.shuffle
| From: | peter at removethisplease dot ddcrew dot com | Date: | Mon, 02 Dec 2013 13:55:24 +0000 |
| Subject: | note 113790 added to function.shuffle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197723@lists.php.net to get a copy of this message | ||
This seems to do reasonably well as a shuffle() that preserves index assocation:
<?php
function ashuffle (&$arr) {
uasort($arr, function ($a, $b) {
return rand(-1, 1);
});
}
?>
Obviously only works if PHP has closures enabled...
----
Server IP: 83.137.20.135
Probable Submitter: 31.160.225.120
----
Manual Page -- http://php.net/manual/en/function.shuffle.php
Edit -- https://master.php.net/note/edit/113790
Del: integrated -- https://master.php.net/note/delete/113790/integrated
Del: useless -- https://master.php.net/note/delete/113790/useless
Del: bad code -- https://master.php.net/note/delete/113790/bad+code
Del: spam -- https://master.php.net/note/delete/113790/spam
Del: non-english -- https://master.php.net/note/delete/113790/non-english
Del: in docs -- https://master.php.net/note/delete/113790/in+docs
Del: other reasons-- https://master.php.net/note/delete/113790
Reject -- https://master.php.net/note/reject/113790
Search -- https://master.php.net/manage/user-notes.php