Differences between iteration and total in the foreach loop statement structure of the smarty template engine

Source: Internet
Author: User
Tags smarty template

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.