我正试图从一个聪明的数组中获取最后一个数组。
这是数组的示例。
Array (2)
0 => Array (3)
id => "1"
name => "John"
age => "25"
1 => Array (3)
id => "2"
name => "Doe"
age => "16"
我尝试了以下方法How to get last element of an array in smarty templates,但不适用于我的情况。
我尝试了{$array|@end}
和{$array.id|@end}
我如何正常撤退{$array[1].id|@end}
,但这并不稳定。我想避免使用foreach
循环
答案 0 :(得分:0)
答案 1 :(得分:0)
如果有帮助,您可以尝试一下
{foreach from=$array key=myId item=i name=foo}
{if $smarty.foreach.foo.last}
<p>This is the last item from the array!</p>
{/if}
{/foreach}