Generating {$num} inside {foreach}

六月ゝ 毕业季﹏ 提交于 2019-12-11 13:07:09

问题


I working on smarty template.

I need to have numbers to my list array

So I tried

{foreach} {$num} {/foreach}

Which prints 0 1 2 3 4 5 ........

I want my numbers to starts from 1 & not 0

How can I achieve this?

OR

Is there any other way to do it ?

Thanks


回答1:


{foreach} {$num|assign:$num+1} {$num} {/foreach}

or

{foreach}{assign var=newnum value=$num+1} {$newnum} {/foreach}



来源:https://stackoverflow.com/questions/3395439/generating-num-inside-foreach

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!