Range ViewHelper <f:range>
The RangeViewHelper returns an array containing a range of integers.
This ViewHelper mimicks PHP's range
function.
The following examples store the result in a variable because an array cannot be outputted directly in a template.
Examples
Increasing range
<f:variable name="result"><f:range start="1" end="5" /></f:variable>
Copied!
{0: 1, 1: 2, 2: 3, 3: 4, 4: 5}
Copied!
Inline increasing range
<f:variable name="result" value="{f:range(start: 1, end: 5)}" />
Copied!
{0: 1, 1: 2, 2: 3, 3: 4, 4: 5}
Copied!
Decreasing range
<f:variable name="result" value="{f:range(start: 5, end: 0)}" />
Copied!
{0: 5, 1: 4, 2: 3, 3: 2, 4: 1, 5: 0}
Copied!
Increasing stepped range
<f:variable name="result" value="{f:range(start: 1, end: 6, step: 2)" />
Copied!
{0: 1, 1: 3, 2: 5}
Copied!
Decreasing stepped range
<f:variable name="result" value="{f:range(start: 5, end: 1, step: 2)" />
Copied!
{0: 5, 1: 3, 2: 1}
Copied!
Go to the source code of this ViewHelper: RangeViewHelper.php (GitHub).
Arguments
The following arguments are available for the range ViewHelper:
end
-
- Type
- integer
- Required
- 1
Last possible value of the sequence.
start
-
- Type
- integer
- Required
- 1
First value of the sequence.
step
-
- Type
- integer
- Default
- 1
indicates by how much the produced sequence is progressed between values of the sequence.