How can I concatenate 2 variables to access array values? I am using this SO post to try to concatenate two variables in twig.

I am very close, but can't seem to get over the hump of rendering the correct syntax.

This is what I am currently using:

 {% for user in plugin.data.users %}
     ...  
     {{ attribute(user, 'foo' ~ loop.index0)|raw|nl2br.bar }}
     ...
 {% endfor %}


This is what I am currently getting back:

Key "foo0"... for array with keys "...does not exist."


What I am trying to create is foo[0], foo[1] etc.

Well, I couldn't figure it out so this is how I did it. If there is a better way, I'd be happy to update the post.

{% set i = 0 %}
    {{ user.foo[i].bar }}
    ...
{% set i = i + 1 %}
I think you need to try and access the array that user.foo would have.
So your code would be something like:

 {% for user in plugin.data.users %}
  ...  
  {{ attribute(user.foo, loop.index0)|raw|nl2br }}
  ...
 {% endfor %}


I haven't tested this though, just going by what I'm sure I remember doing once...