属性名称 | 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 访问foreache属性的foreach循环名 |
foreach loops are an alternative to section loops.
foreach is used to loop over a single associative array.
The syntax for foreach is much easier than section, but as a tradeoff it can only be used for a single array. foreach tags must be paired with /foreach tags. Required parameters are from and item.
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.
The from variable (usually an array of values) determines the number of times foreach will loop.
foreachelse is executed when there are no values in the from variable.
foreach循环是选择性的section循环.
foreach用于遍历关联数组.
foreach的语法比section简单的多,但是作为一个折中它只能用于简单数组.
foreach的标签必须成对,必须的参数是from和item.
循环的名称是字母,数字和下划线.
循环可以互相嵌套,被嵌套的循环之间的名字必须是独立的.
from变量(通常是一个数组的值)决定循环的次数
foreachelse 在from变量没有值的时候被执行