krsort

The krsort filter sorts an array or hash in reverse order by its keys.

You would typically save the sorted array back to the original variable or to a new variable.

{% set array = array|krsort %}

{% set hash = hash|krsort %}

You can use this filter within a for loop.

{% for item in items|krsort %}
...
{% endfor %}

You can also use this filter in combination with the join filter to sort and output the array values in one step.

{{ [5,8,2,3]|krsort|join(', ') }}

That would output: 8, 5, 3, 2

< Back to the list of filters