note 110678 modified in function.uasort by aharvey
| From: | aharvey@php.net | Date: | Fri, 23 Nov 2012 01:41:33 +0000 |
| Subject: | note 110678 modified in function.uasort by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192107@lists.php.net to get a copy of this message | ||
To shuffle assoc array preserving keys just do this:
<?php uasort(
$array,
function ($a, $b) {
return mt_rand(0, 1) > 0 ? 1 : -1;
}
); ?>
--was--
To shuffle assoc array preserving keys just do this:
<?php uasort(
$array,
function ($a, $b) {
return rand(0, 1) > 0 ? 1 : -1;
}
); ?>
http://php.net/manual/en/function.uasort.php