symfony - Reverse array in Twig -
i'm doing file explorer symfony 2.5 , php 5.3
in controller return array view (result of calling scandir();
on directory)
the array contains "months". (january, february, march...) , display in bootstrap accordion.
i want order descending array like:
december -> november -> october -> september ...
we can see {{ months in month|sort|reverse }}
doesnt work here.
how can please?
you need sort array index, otherwise sort array alphabetically:
{% set months = {1: 'january', 2: 'february', 3: 'march', 4: 'april', 5: 'may', 6: 'june', 7: 'july', 8: 'august', 9: 'september', 10: 'october', 11: 'november', 12: 'december'} %} {% month in months|reverse %} {{ month }} {% endfor %}
Comments
Post a Comment