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