Home > Backend Development > PHP Tutorial > 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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-18 09:15:56
Original
1455 people have browsed it

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>
Copy after login
Copy after login

{/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>
Copy after login
Copy after login

{/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

{foreach $items as $item}
    {if $item@last}
        //这里就是最后一条数据了
    {/if}
{/foreach}
Copy after login
Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template