Home  >  Article  >  Backend Development  >  How to get the value of the last loop of foreach in smarty template

How to get the value of the last loop of foreach in smarty template

WBOY
WBOYOriginal
2016-08-18 09:15:561386browse

How to get the value of the last loop of foreach in smarty template
As shown in the picture, an array is passed from the background to the front desk. Using foreach loop, I just want to get the value of invalid_num in the last loop. How should I get it

{foreach from=$bonus item=item name=bonus}

{/foreach}
I used it outside the loop.
I used this judgment and did not get
{if $smarty.foreach.bonus.last}

<code>{$item.Invalid_num}</code>

{/if}

Reply content:

How to get the value of the last loop of foreach in smarty template
As shown in the picture, an array is passed from the background to the front desk. Using foreach loop, I just want to get the value of invalid_num in the last loop. How should I get it

{foreach from=$bonus item=item name=bonus}

{/foreach}
I used it outside the loop.
I used this judgment and did not get
{if $smarty.foreach.bonus.last}

<code>{$item.Invalid_num}</code>

{/if}

Save all invalid_num values ​​into the array according to the current $key, count length, and then take them out, $array[$count - 1]

Reference documentation[]()
Reference documentation

<code class="php">{foreach $items as $item}
    {if $item@last}
        //这里就是最后一条数据了
    {/if}
{/foreach}</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn