Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Convert foreach in php to for in Volt template

Hi all, I have a code, please give me convert to volt template:

I want to turn $i+1 increase per unit when the foreach loop in Volt template

<?php $i=1; foreach($arr as $value){
echo $i;
$i++;
}?>


107.4k
Accepted
answer
edited Mar '16
{% set i = 1 %}
{% for value in arr %}
{{ i }}
{% set i += 1 %}
{% endfor %}

ok thanks so much