From: Fabien Potencier Date: Sun, 18 Dec 2011 14:08:12 +0000 (+0100) Subject: fixed the random function X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=11943fbe21576997e0d3a053ee99197d6a6c4d32;p=web%2Fkonrad%2Ftwig.git fixed the random function --- diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 9e5cf20..78f0660 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -258,11 +258,13 @@ function twig_random($values) return $values; } - if (is_object($values) && !$values instanceof Countable) { + if (is_object($values)) { $values = iterator_to_array($values); } - return $values[mt_rand(0, count($values) - 1)]; + $keys = array_keys($values); + + return $values[$keys[mt_rand(0, count($values) - 1)]]; } /**