如何在 Smarty 数组循环中的最后一次迭代之前获取项目

How to get the item before the last iteration in the loop of a Smarty array

你好聪明的(y)女孩和男孩!

不幸的是我找不到答案,当然我是 Smarty 的新手....希望你能帮我解决!

我正在寻找 smarty foreach 循环的最后一个项目之前的项目。因此,例如,如果我的数组有 8 次迭代,我需要第 7 次迭代,如果有 3 次迭代,我需要第二次......等等。

我怎样才能得到它?最后一张我可以拿到,但是前面那张怎么拿到?

有“{foreach} 属性”:@index、@iteration、@first、@last、@show、@total。 您的案例示例:

{foreach $array as $a}
  {if $a@iteration == $a@total-1}
  last-1 value is: $a
  {/if}
{/foreach}