Home > Backend Development > PHP Tutorial > Detailed explanation of the implementation of Smarty foreach to control the number of loops_PHP tutorial

Detailed explanation of the implementation of Smarty foreach to control the number of loops_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:01:00
Original
748 people have browsed it

1. You can try {$array| count}.
2.

Copy code The code is as follows:

{foreach from=$variable key=key name =name iteam=value}
{$variable|@count} // Get the array length
{$smarty.foreach.loop.index} // Get the subscript of the current loop array element, starting with 0
{$smarty.foreach.loop.iteration} // Get the current number of loops, starting with 1
{$smarty.foreach.loop.first} // When true, mark the first execution of the loop
{$ smarty.foreach.loop.last} // When true, mark the last execution of the loop
{$smarty.foreach.name.last} // When true, mark the last execution of the loop
{$smarty. foreach.loop.show} // Whether to display
currently {$smarty.foreach.loop.total} // Number of loops
{/foreach}

3. Control Number of loops
Copy code The code is as follows:

{foreach name=infolist from=$VIDEO_INFO_LIST item=infolist}
{assign var=floor value=$smarty.foreach.infolist.index}
{if $floor<5%} {*or if $smarty.foreach.infolist.iteration <5*}
  • {$infolist%}

  • {/if}
    {/foreach}

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328022.htmlTechArticle1. You can try {$array| count}. 2. Copy the code as follows: {foreach from=$variable key=key name=name itam=value} {$variable|@count} // Get the array length {$smarty.forea...
    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
    Latest Issues
    smarty turns on caching garbled characters
    From 1970-01-01 08:00:00
    0
    0
    0
    Why does tp use smarty template? ?
    From 1970-01-01 08:00:00
    0
    0
    0
    How do you use smarty to integrate laravel5?
    From 1970-01-01 08:00:00
    0
    0
    0
    Two ways to install smarty
    From 1970-01-01 08:00:00
    0
    0
    0
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template