如何在smarty中获取foreach循环的最后一个索引值,我是smarty的新手。我使用过以下代码,但它不起作用。
{foreach from=$cityList key=myId item=i name=foo}
{$i.location_name}{if $main_smarty.foreach.foo.last}<hr>{else}-{/if}
{/foreach}我想知道他们的最后一个城市名称是什么,然后是水平线,否则就是印度-美国-日本-但最后是日本-中国
在.php中,我使用
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;
query to find citylist
$main_smarty->assign('cityList',$cityList);
?>发布于 2010-06-25 20:53:03
如果$arr是您传递给{foreach}的数组,则可以这样做:
{$arr|@end}事实上,它不需要在{foreach}中调用
https://stackoverflow.com/questions/3117997
复制相似问题