In PHP I would do this:
foreach( $array as $key => $value ) { echo $another_array[$key]; }
I can’t see how to do that in Twig (in Symfony2). I’ve tried various things, but this would seem the obvious answer, but it doesn’t work. It returns a ‘Item “the_index” for “Array” does not exist in’ error.
{% for value in array %} {% set the_index = loop.index %} {{ another_array.the_index }}
Any ideas?
Advertisement
Answer
The fastest way:
{% for key,value in array %} {{ another_array[key] }} {% endfor %}