Skip to content

Instantly share code, notes, and snippets.

@mmeyer2k
Created April 19, 2022 18:15
Show Gist options
  • Save mmeyer2k/ae6427a9652633ec3fd754d9406a8c5d to your computer and use it in GitHub Desktop.
Save mmeyer2k/ae6427a9652633ec3fd754d9406a8c5d to your computer and use it in GitHub Desktop.
Secure array_shuffle
<?php
function array_shuffle_secure(array $input): array {
$output = [];
while ($arr) {
$arr = array_values($arr);
$char = random_int(0, count($arr) - 1);
$output[] = $arr[$char];
unset($arr[$char]);
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment