In the foreach loop statement structure of the smarty template engineIterationAndTotalDifferences:
- Total displays the total number of times of loop execution.
- Iteration displaysCurrentNumber of cycles executed
Therefore, if you want to print the current serial number of each loop, you can use<{$ Smarty. foreach. foreachname. Iteration}>
For example:
<{Foreach from = $ Article item = Val key = key name = WHF}>
<{$ Smarty. foreach. WHF. Iteration}> --- <{$ key}> --> <{$ Val}> <br>
<{/Foreach}>
Current total cycle <{$ smarty. foreach. WHF. iteration-1}> times // note that the total number of cycles refers to the cycles in the array
// Including this loop
The result is similar:
1 --- id --> 1
2 --- article_id --> 1
3 --- uid --> 2
4 --- cat_id --> 2
The current cycle is 4 times in total
While
<{Foreach from = $ Article item = Val key = key name = WHF}>
<{$ Smarty. foreach. WHF. Total}> --- <{$ key}> --> <{$ Val}> <br>
<{/Foreach}>
Current total number of <{$ smarty. foreach. WHF. Total}> times
The result is similar:
4 --- id --> 1
4 --- article_id --> 1
4 --- uid --> 2
4 --- cat_id --> 2
The current cycle is 4 times in total
ArticleAuthor:Wen developers _ Xiao Fei
Reprinted Please note: http://www.cnblogs.com/hongfei/archive/2011/12/09/smarty-foreach-iteration-total.html