Skip to content

Instantly share code, notes, and snippets.

View marcsoler's full-sized avatar
🤪

Marc Solèr marcsoler

🤪
View GitHub Profile
@marcsoler
marcsoler / _shuffle-associtive.php
Last active January 12, 2021 01:27
Shuffle associative array while preserving keys (Fisher–Yates shuffle algorithm)
<?php
function fisherYatesShuffleAssoc(&$items, $seed)
{
$di = $items;
@mt_srand($seed);
$items = array_values($items);
for ($i = count($items) - 1; $i > 0; $i--)
{
$j = @mt_rand(0, $i);