Skip to content

Commit

Permalink
added missing preserveKeys argument to the reverse filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 3, 2011
1 parent c6917a2 commit 6e3a1c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* 1.4.0

* added missing preserveKeys argument to the reverse filter
* fixed macros containing filter tag calls

* 1.4.0-RC2 (2011-11-27)
Expand Down
9 changes: 5 additions & 4 deletions lib/Twig/Extension/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,21 +412,22 @@ function twig_get_array_keys_filter($array)
/**
* Reverses an array.
*
* @param array|Traversable $array An array or a Traversable instance
* @param array|Traversable $array An array or a Traversable instance
* @param Boolean $preserveKeys Whether to preserve key or not
*
* return array The array reversed
*/
function twig_reverse_filter($array)
function twig_reverse_filter($array, $preserveKeys = false)
{
if (is_object($array) && $array instanceof Traversable) {
return array_reverse(iterator_to_array($array));
return array_reverse(iterator_to_array($array), $preserveKeys);
}

if (!is_array($array)) {
return array();
}

return array_reverse($array);
return array_reverse($array, $preserveKeys);
}

/**
Expand Down

0 comments on commit 6e3a1c4

Please sign in to comment.