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?
The fastest way:
{% for key,value in array %}
{{ another_array[key] }}
{% endfor %}
You can use the attribute function.
{{ attribute(another_array, the_index) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With