How to determine whether the php loop is the last one

Source: Internet
Author: User
How can I determine whether php loop is the last one? {Foreachfrom = $ myArrayitem = foo} & lt; li & gt; {$ foo} & lt;/li & gt ;{/ foreach}. I think this is the case, you can also check the number of data records when reading the records. When assign is sent to the foreground page, how does one determine whether the php loop is the last one?
{Foreach from = $ myArray item = foo}
  • {$ Foo}

  • {/Foreach}

    ------ Solution --------------------
    I think this is the case. we can also check the number of data records when reading the records. When assign arrives at the front-end page, the number of times of the current loop can be obtained by loop. although I don't know which parameter the number of current cycles is obtained by The smarty foreach loop, you can check it, we should be able to check this. compare the current number of cycles with the total number of data, that is, the total number of cycles. if the number is equal, it is the last loop.
    ------ Solution --------------------
    1. you are not a php loop, but a template language loop.
    2. your template language is similar to the smarty template language, but it cannot be determined. Many template engines use this format.
    3. if you can confirm it is the smarty template engine, there is a last attribute that meets your needs.
    . Last when the current foreach loop is executed until the last time, the last is set to true.
    {* Add a horizontal line at the end of the list *}
    {Foreach from = $ items key = part_id item = prod name = products}
    {$ Prod} {if $ smarty. foreach. products. last} {else}, {/if}
    {Foreachelse}
    ... Content...
    {/Foreach}

    There are also many practical attributes available, such as index, iteration, first, and total.
    These are what the so-called efficient template engine with a smarty shape but no smarty quality cannot do.

    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.