使用 for 循环表示树枝中的变量

represent a variable in twig using for loop

在我的服务中,我 return 一个如下所示的数组:

$array = [
    'bible_anagram_word'    => $result->getBibleAnagramWord(),
    'word_1'                => $result->getWord1(),
    'word_2'                => $result->getWord2(),
    'word_3'                => $result->getWord3(),
    ...
    'word_22'               => $result->getWord22(),
    'word_23'               => $result->getWord23(),
    'word_24'               => $result->getWord24(),
    'word_25'               => $result->getWord25(),
    'Bible_verse_reference' => $result->getBibleVerseReference(),
    'Bible_verse_text'      => $result->getBibleVerseText(),
    'Bible_translation'     => $result->getBibleTranslation(),
];

如何在这个 for 循环中表示 document.word_##

{% for i in 1..25 %}
    {{ document.word_ ~ i|slice(0,1) }}
{% endfor %}

在 PHP 这个代码是:

substr ( $this->document['word_'.$i] , 0 , 1 )

我失败的尝试包括:

这应该可以解决问题

{{ attribute(document, 'word_' ~ i) }} 

更多关于 attribute function