3v4l.org

run code in 300+ PHP versions simultaneously
<?php function preserve_shuffle(&$arr) #Shuffles the key-value associations in an array. { $keys = array_keys($arr); #extract the keys from the array. shuffle($keys); for ($index = 0, $length = count($keys); $index < $length; ++$index) { $result[$keys[$index]] = $arr[$keys[$index]]; } $arr = $result; } $arr = ["a" => "apple", "b" => "banana", "c" => "capsicum", "d" => "dill"]; preserve_shuffle($arr); var_export($arr);

preferences:
29.69 ms | 402 KiB | 5 Q