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
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:01:00744browse

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...
    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