- var_export: documentation ( source)
- shuffle: documentation ( source)
- array_keys: documentation ( source)
<?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);