1

I'm trying to save some values into a multiarray on Twig, but for some reason, it's not working.

I want to save in an array a list of users and some values of them. I am using merge function to create the multi array.

{% for result in results %}
        {% set users = users|merge({ ('name'~loop.index):result.name,('age'~loop.index):result.age,('credits'~loop.index):result.credits}) %}
{% endfor %}
1
  • 2
    What does "is not working" mean? Commented Mar 16, 2015 at 23:53

1 Answer 1

6

Try this out :

{% set users = [] %}
{% for result in results %}
    {% set users = users|merge([{ 'name' : result.name, 'age' : result.age, 'credits' : result.credits }]) %}
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.