Skip to content

Instantly share code, notes, and snippets.

@Quinten
Created May 9, 2011 10:59
Show Gist options
  • Save Quinten/962358 to your computer and use it in GitHub Desktop.
Save Quinten/962358 to your computer and use it in GitHub Desktop.
shuffle an array while preserving keys
<?php
function shuffle_assoc($list) {
if (!is_array($list)) return $list;
$keys = array_keys($list);
shuffle($keys);
$random = array();
foreach ($keys as $key)
$random[$key] = $list[$key];
return $random;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment