Shuffle/Randomize Array while Preserving Keys


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function shuffle_with_keys(&$array) {
  2. $aux = array();
  3. $keys = array_keys($array);
  4. shuffle($keys);
  5. foreach($keys as $key) {
  6. $aux[$key] = $array[$key];
  7. unset($array[$key]);
  8. }
  9. $array = $aux;
  10. }

URL: http://us3.php.net/manual/en/function.shuffle.php#83007

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.