PHP 8.5.0 Beta 1 available for testing

Voting

: one plus seven?
(Example: nine)

The Note You're Voting On

andjones at gmail dot com
14 years ago
Shuffle associative and non-associative array while preserving key, value pairs. Also returns the shuffled array instead of shuffling it in place.

<?php

function shuffle_assoc($list) {
if (!
is_array($list)) return $list;

$keys = array_keys($list);
shuffle($keys);
$random = array();
foreach (
$keys as $key)
$random[$key] = $list[$key];

return
$random;
}

?>

<< Back to user notes page

To Top