From 11943fbe21576997e0d3a053ee99197d6a6c4d32 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 18 Dec 2011 15:08:12 +0100 Subject: [PATCH] fixed the random function --- lib/Twig/Extension/Core.php | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) 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)]]; } /** -- 1.7.2.5