Symfony2 / Twig - getting array from dynamic array key

前端 未结 3 1200
遇见更好的自我
遇见更好的自我 2021-02-12 18:32

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 Sym

相关标签:
3条回答
  • 2021-02-12 19:03
    <ul>
        {% for value in array %}
           {% set the_index = attribute(another_array,  loop.index) %}
           <li>{{ the_index }}</li>
        {% endfor %}
    </ul>
    
    0 讨论(0)
  • 2021-02-12 19:04

    You can use the attribute function.

    {{ attribute(another_array, the_index) }}
    
    0 讨论(0)
  • 2021-02-12 19:05

    The fastest way:

    {% for key,value in array %}
      {{ another_array[key] }}
    {% endfor %}
    
    0 讨论(0)
提交回复
热议问题