Skip to content
Snippets Groups Projects
Commit 19e41c26 authored by xamgore's avatar xamgore
Browse files

New function for shuffling associative arrays

There is a problem at the standard (STL) realization: it doesn't work with assoc arrays, so [0 => 123, 5 => 123] is transformed into [0 => 123, 1 => 123].

`Arr::shuffle_assoc` saves keys.
parent bbd6d462
Branches
Tags
No related merge requests found
......@@ -10,7 +10,22 @@
*/
class Kohana_Arr {
/**
public static function shuffle_assoc($list) {
if (!is_array($list))
return $list;
$keys = array_keys($list);
shuffle($keys);
$random = [];
foreach ($keys as &$key) {
$random[$key] = $list[$key];
}
return $random;
}
/**
* @var string default delimiter for path()
*/
public static $delimiter = '.';
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment