Home  >  Article  >  php教程  >  Smarty foreach控制循环次数的实现详解

Smarty foreach控制循环次数的实现详解

WBOY
WBOYOriginal
2016-06-13 11:43:25768browse

1.可以用{$array| count} 来试试。
2.

复制代码 代码如下:


{foreach from=$variable key=key name=name iteam=value}
    {$variable|@count}     // 获取数组长度
    {$smarty.foreach.loop.index}    // 获取当前循环数组元素下标,以0开始
    {$smarty.foreach.loop.iteration}    // 获取当前循环次数,以1开始
    {$smarty.foreach.loop.first}    // 为true时,标记循环第一次执行
    {$smarty.foreach.loop.last}    // 为true时,标记循环最后一次执行
 {$smarty.foreach.name.last}    // 为true时,标记循环最后一次执行
    {$smarty.foreach.loop.show}    // 当前是否显示
    {$smarty.foreach.loop.total}    // 循环次数
{/foreach}


3、控制循环次数

复制代码 代码如下:


{foreach name=infolist from=$VIDEO_INFO_LIST item=infolist}
{assign var=floor value=$smarty.foreach.infolist.index}
{if $floor 

  • {$infolist%}

  • {/if}
    {/foreach}

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn