print index in php twig file

The `loop` variable

Inside of a for loop block you can access some special variables:

VariableDescription
loop.indexThe current iteration of the loop. (1 indexed)
loop.index0The current iteration of the loop. (0 indexed)
loop.revindexThe number of iterations from the end of the loop (1 indexed)
loop.revindex0The number of iterations from the end of the loop (0 indexed)
loop.firstTrue if first iteration
loop.lastTrue if last iteration
loop.lengthThe number of items in the sequence
loop.parentThe parent context

{% for user in users %}
    {{ loop.index }} - {{ user.username }}
{% endfor %}