Home > Backend Development > PHP Tutorial > Smarty foreach控制循环次数的实现详解_php技巧

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

WBOY
Release: 2016-05-17 08:57:17
Original
1144 people have browsed it
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}

    Related labels:
    source:php.cn
    Statement of this Website
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template