Guillaume Guillaume - 24 days ago 6
PHP Question

Twig for loop and array with key

I use Twig and I have an array with key 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 I can do this ?

Thank you

Answer

I found the answer :

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