Smarty的foreach语句如何跳出循环? {foreach from=$list key="j" item="listCell"} {if $j>=15 } {* 想跳出循环 *} {/if}{/foreach}有跳出循环语句吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一般这种情况我都是在给assign前就把数据整理好了,然后再赋值给smarty的去页面循环显示的。。 {foreach from=$list key="j" item="listCell"} {if $j>=15 } {* break; *} {/if}{/foreach} {foreach name=foo item=listCell from=$list}{if $smarty.foreach.foo.iteration>15} {break}{/if}{/foreach} 看你乍样跳吧continuebreak 两个都可以。另外:楼上的拼错了吧?? 弱弱的问一声: 在smarty里有continue,break吗? 你们大家用过吗?俺试了continue,break都不行啊!在manual↓也没找到http://www.smarty.net/manual/en/language.function.foreach.php 代码都贴出来了 怎么可能不行呢 3L的代码就可以 不过{if $j>=15 } ==> {if $j>=15} 向lz道歉!!!3L的不可以 我之前测试错误 smarty不可以用break理由是不需要因为逻辑控制应该在php侧完成 tpl这边不需要的数据应该在php侧就把它剔除出去 否则逻辑显示的分离就等于没做到 可能是我写的有问题吧,我重新写给你看看{foreach name=foo item=listCell from=$list}{if $smarty.foreach.foo.iteration>15} //$smarty.foreach.foo.iteration代表foreach循环次数{*这里是你的语句*}{/if}{/foreach} http://www.smarty.net/forums/viewtopic.php?p=54883看2 3L的回答 谢谢诸位!看来smarty的逻辑功能比较弱,俺再修改PHP的赋值... php如何打印金字塔 解析 3DES PKCS7 急在线等 The specified URL cannot be found. php+mssql:mssql_connect Unable to connect to server $result=mysql_query($query);返回的是什么类型的值? 如何用PHP +XML 制作类别列表 全部变量的问题? 关于文件上传问题,很奇怪,获取不下来,在线等急啊 如何开启curl函数 怎样删除第一条数据? PHP 写入 MySQL 数据库问题 [50分]如何通过php代码来控制select中某个option为选中状态
{if $j>=15 } {* break; *} {/if}{/foreach}
{if $smarty.foreach.foo.iteration>15}
{break}
{/if}
{/foreach}
continue
break
两个都可以。另外:楼上的拼错了吧??
http://www.smarty.net/manual/en/language.function.foreach.php
不过{if $j>=15 } ==> {if $j>=15}
3L的不可以 我之前测试错误
理由是不需要
因为逻辑控制应该在php侧完成 tpl这边不需要的数据应该在php侧就把它剔除出去 否则逻辑显示的分离就等于没做到
{if $smarty.foreach.foo.iteration>15} //$smarty.foreach.foo.iteration代表foreach循环次数
{*这里是你的语句*}
{/if}
{/foreach}
看2 3L的回答