【发布时间】:2011-03-08 06:36:33
【问题描述】:
如何在 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);
?>
【问题讨论】:
-
请提供更多代码,以便我们确定问题所在,您提供的 sn-p 在我看来没问题,应该可以正常工作