public function shuffle(array $array, $preserveKeys = true): array
    {
        if ($array === []) {
            return $array;
        }
        if ($preserveKeys) {
            $keys = array_keys($array);
            shuffle($keys);
            $shuffledArray = [];
            foreach ($keys as $key) {
                $shuffledArray[$key] = $array[$key];
            }
            $array = $shuffledArray;
        } else {
            shuffle($array);
        }
        return $array;
    }
public function shuffle(array $array, $preserveKeys = true): array
    {
        if ($array === []) {
            return $array;
        }
        if ($preserveKeys) {
            $keys = array_keys($array);
            shuffle($keys);
            $shuffledArray = [];
            foreach ($keys as $key) {
                $shuffledArray[$key] = $array[$key];
            }
            $array = $shuffledArray;
        } else {
            shuffle($array);
        }
        return $array;
    }
public function shuffle ( array $ array , $ preserveKeys = true ) : array { if ( $ array === [ ] ) { return $ array ; } if ( $ preserveKeys ) { $ keys = array_keys ( $ array ) ; shuffle ( $ keys ) ; $ shuffledArray = [ ] ; foreach ( $ keys as $ key ) { $ shuffledArray [ $ key ] = $ array [ $ key ] ; } $ array = $ shuffledArray ; } else { shuffle ( $ array ) ; } return $ array ; }
Shuffle an array

Randomizes entries an array with the option to preserve the existing keys.
When this option is set to false, all keys will be replaced

@param array $array
@param bool $preserveKeys Wether to preserve the keys when shuffling the array
@return array The shuffled array
Shuffle an array