How could I declare variables in a loop using Twig from a “users” array of objects “user” retrieved from the controller?
user1 = “user1”
user2 = “user2”
…
userN = “userN” (with N length of the array)
{% for user in users %}
{% set user1 = "user1" %}
{% set user2 = "user2" %}
...
{% endfor %}
Twig gives you different loop variables, that you can use in the loops.
http://twig.sensiolabs.org/doc/tags/for.html#the-loop-variable
As for implementation of dynamic variable names – Twig does not support this, AFAIK.
In your case, I guess you need to refactor your application logic to work inside the loop: