These are extended operations (e.g., sort, reverse) for one dimensional and two dimensional arrays in Twig framework:
1D Array
Without Key Sort and Reverse
{% for key, value in array_one_dimension %}
<div>{{ key }}</div>
<div>{{ value }}</div>
{% endfor %}
Key Sort
{% for key, value in array_one_dimension|keys|sort %}
<div>{{ key }}</div>
<div>{{ value }}</div>
{% endfor %}
Key Sort and Reverse
{% for key, value in array_one_dimension|keys|sort|reverse %}
<div>{{ key }}</div>
<div>{{ value }}</div>
{% endfor %}
2D Arrays
Without Key Sort and Reverse
{% for key_a, value_a in array_two_dimension %}
{% for key_b, value_b in array_two_dimension[key_a] %}
<div>{{ key_b }}</div>
<div>{{ value_b }}</div>
{% endfor %}
{% endfor %}
Key Sort on Outer Array
{% for key_a, value_a in array_two_dimension|keys|sort %}
{% for key_b, value_b in array_two_dimension[key_a] %}
<div>{{ key_b }}</div>
<div>{{ value_b }}</div>
{% endfor %}
{% endfor %}
Key Sort on Both Outer and Inner Arrays
{% for key_a, value_a in array_two_dimension|keys|sort %}
{% for key_b, value_b in array_two_dimension[key_a]|keys|sort %}
<div>{{ key_b }}</div>
<div>{{ value_b }}</div>
{% endfor %}
{% endfor %}
Key Sort on Outer Array & Key Sort and Reverse on Inner Array
{% for key_a, value_a in array_two_dimension|keys|sort %}
{% for key_b, value_b in array_two_dimension[key_a]|keys|sort|reverse %}
<div>{{ key_b }}</div>
<div>{{ value_b }}</div>
{% endfor %}
{% endfor %}
Key Sort and Reverse on Outer Array & Key Sort on Inner Array
{% for key_a, value_a in array_two_dimension|keys|sort|reverse %}
{% for key_b, value_b in array_two_dimension[key_a]|keys|sort %}
<div>{{ key_b }}</div>
<div>{{ value_b }}</div>
{% endfor %}
{% endfor %}
Key Sort and Reverse on Both Outer and Inner Array
{% for key_a, value_a in array_two_dimension|keys|sort|reverse %}
{% for key_b, value_b in array_two_dimension[key_a]|keys|sort|reverse %}
<div>{{ key_b }}</div>
<div>{{ value_b }}</div>
{% endfor %}
{% endfor %}
foreach
loop. – Josh