foreach,foreachelse
- Table of Contents目录
- iteration
- first
- last
- show
- total
Attribute Name | Type | Required | Default | Description |
---|---|---|---|---|
from | string | Yes | n/a | The name of the array you are looping through |
item | string | Yes | n/a | The name of the variable that is the current element |
key | string | No | n/a | The name of the variable that is the current key |
name | string | No | n/a | The name of the foreach loop for accessing foreach properties |
属性 | 类型 | 是否必须 | 缺省值 | 描述 |
---|---|---|---|---|
from | string | Yes | n/a | 待循环数组的名称 |
item | string | Yes | n/a | 当前处理元素的变量名称 |
key | string | No | n/a | 当前处理元素的键名 |
name | string | No | n/a | 该循环的名称,用于访问该循环 |
foreach loops are an alternative tosection loops.foreach is used to loop over a single associative array. The syntax forforeach is much easier thansection , but as a tradeoff it can only be used for a single array.foreach tags must be paired with/foreach tags. Required parameters arefrom anditem . The name of the foreach loop can be anything you like, made up of letters, numbers and underscores.foreach loops can be nested, and the nested foreach names must be unique from each other. Thefrom variable (usually an array of values) determines the number of timesforeach will loop.foreachelse is executed when there are no values in thefrom variable.
foreach 是除 section 之外处理循环的另一种方案(根据不同需要选择不同的方案).
foreach 用于处理简单数组(数组中的元素的类型一致),它的格式比 section 简单许多,缺点是只能处理简单数组.
foreach 必须和 /foreach 成对使用,且必须指定 from 和 item 属性.
name 属性可以任意指定(字母、数字和下划线的组合).
foreach 可以嵌套,但必须保证嵌套中的 foreach 名称唯一.
from 属性(通常是数组)决定循环的次数.
foreachelse 语句在 from 变量没有值的时候被执行.
Example 7-4. foreach
|