我正在尝试从一个聪明的数组中获取最后一个数组。
这里是数组的示例。
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
循环
如果有帮助,您可以尝试一下
{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}