Smarty foreach控制循环次数的一些方法_php实例
Jun 07, 2016 pm 05:12 PM1、在 smarty 中数组是经常会用到的,循环遍历数组用 section 或者 foreach ,如何得到数组长度或者判断一个数组个数呢?可以用{$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 {*或者 if $smarty.foreach.infolist.iteration
{/if}
{/foreach}

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to determine the number of foreach loop in php

What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList?

PHP returns an array with key values flipped

PHP returns the current element in an array

How to iterate through the properties of an object using the forEach function?

How to use PHP and Smarty to achieve front-end and back-end separation development

A preliminary study on the template engine Smarty in PHP

What is the difference between foreach and for loop
