usort($a, function($elem_1, $elem_2)
{
return rand(0, 1) == 1 ? 1 : -1;
});
<?php
$input = range('a', 'z');
$result = my_shuffle($input);
$result2 = my_shuffle($input, true);
var_dump($input);
var_dump($result);
var_dump($result2);
function my_shuffle(array $input, bool $preserve_keys = false): array
{
$result = [];
while (count($input) > 0) {
$rand_key = array_rand($input, 1);
if ($preserve_keys) {
$result[$rand_key] = $input[$rand_key];
} else {
$result[] = $input[$rand_key];
}
unset($input[$rand_key]);
}
return $result;
}