Voting

: three plus six?
(Example: nine)

The Note You're Voting On

ahmad at ahmadnassri dot com
15 years ago
shuffle for associative arrays, preserves key=>value pairs.
(Based on (Vladimir Kornea of typetango.com)'s function)

<?php
function shuffle_assoc(&$array) {
$keys = array_keys($array);

shuffle($keys);

foreach(
$keys as $key) {
$new[$key] = $array[$key];
}

$array = $new;

return
true;
}
?>

*note: as of PHP 5.2.10, array_rand's resulting array of keys is no longer shuffled, so we use array_keys + shuffle.

<< Back to user notes page

To Top