symfony - Extracting integer from a for loop iteration in php, twig -


i iterating through arrays of data in php (twig template).

{% subscription in form.peereventsubscriptions %} <option value='{{typedefevent[0]}}'>-{{ form_label(subscription.eventtypehumanized) }}-</option> {% endfor %} 

the data text. possible simultaneously integer update array index:

typedefevent[i] 

? , remember, twig template.

there's no need introduce variable here. quoting the docs:

inside of for loop block can access special variables:

variable        description loop.index      current iteration of loop. (1 indexed) loop.index0     current iteration of loop. (0 indexed) loop.revindex   number of iterations end of loop (1 indexed) loop.revindex0  number of iterations end of loop (0 indexed) loop.first      true if first iteration loop.last       true if last iteration loop.length     number of items in sequence loop.parent     parent context 

so can write template this:

{% subscription in form.peereventsubscriptions %}   <option value='{{typedefevent[loop.index0]}}'>-{{ form_label(subscription.eventtypehumanized) }}-</option> {% endfor %} 

Comments