Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php中的for循环迭代中提取整数,twig_Php_Symfony_Twig - Fatal编程技术网

从php中的for循环迭代中提取整数,twig

从php中的for循环迭代中提取整数,twig,php,symfony,twig,Php,Symfony,Twig,我目前正在用php(细枝模板)遍历数据数组 ?? 谢谢并记住,这是一个细枝模板。{%set i=0%} {% for subscription in form.peerEventSubscriptions %} <option value='{{typeDefEvent[0]}}'>-{{ form_label(subscription.eventTypeHumanized) }}-</option> {% endfor %} {% set i = 0 %} &l

我目前正在用php(细枝模板)遍历数据数组

?? 谢谢并记住,这是一个细枝模板。

{%set i=0%}
{% for subscription in form.peerEventSubscriptions %}
<option value='{{typeDefEvent[0]}}'>-{{ form_label(subscription.eventTypeHumanized) }}-</option>
{% endfor %}
{% set i = 0 %}
   <select name="myPostVar">
{% for subscription in form.peerEventSubscriptions%}
<option value='{{typeDefEvent[i]}}'>-{{ form_label(subscription.eventTypeHumanized) }}-</option>
{% set i = i+1 %}
{% endfor %}
{%的订阅格式为.peerEventSubscriptions%} -{{form_label(subscription.eventTypeHumanized)}- {%set i=i+1%} {%endfor%}

基本上使用模板标签设置和更新循环中的迭代器,这里不需要引入其他变量。引述:

在循环块的
内部,您可以访问一些特殊变量:

因此,您可以这样编写模板:

{% for subscription in form.peerEventSubscriptions %}
  <option value='{{typeDefEvent[loop.index0]}}'>-{{ form_label(subscription.eventTypeHumanized) }}-</option>
{% endfor %}
{%用于表单中的订阅。peerEventSubscriptions%}
-{{form_label(subscription.eventTypeHumanized)}-
{%endfor%}
Variable        Description
loop.index      The current iteration of the loop. (1 indexed)
loop.index0     The current iteration of the loop. (0 indexed)
loop.revindex   The number of iterations from the end of the loop (1 indexed)
loop.revindex0  The number of iterations from the end of the loop (0 indexed)
loop.first      True if first iteration
loop.last       True if last iteration
loop.length     The number of items in the sequence
loop.parent     The parent context
{% for subscription in form.peerEventSubscriptions %}
  <option value='{{typeDefEvent[loop.index0]}}'>-{{ form_label(subscription.eventTypeHumanized) }}-</option>
{% endfor %}