Twig for loop for arrays with keys

Guillaume picture Guillaume · Apr 24, 2012 · Viewed 239.8k times · Source

I use Twig and I have an array with keys like this:

array[1] = "alpha"
array[2] = "bravo"
array[3] = "charlie"
array[8] = "delta"
array[9] = "echo"

And I would like to get the key (1,2,3,8,9) and the content (alpha, bravo, charlie, delta, echo) in a loop to get all value of this array.

How do I solve this problem?

Answer

Guillaume picture Guillaume · Apr 24, 2012

I found the answer :

{% for key,value in array_path %}
    Key : {{ key }}
    Value : {{ value }}
{% endfor %}