range

Returns a list containing an arithmetic progression of integers:

整数の算術級数を含むリストを返します。
1
2
3
4
5
{% for i in range(0, 3) %}
    {{ i }},
{% endfor %}

{# outputs 0, 1, 2, 3, #}

When step is given (as the third parameter), it specifies the increment (or decrement for negative values):

step が (3 番目のパラメーターとして) 指定されると、インクリメント (負の値の場合はデクリメント) が指定されます。
1
2
3
4
5
{% for i in range(0, 6, 2) %}
    {{ i }},
{% endfor %}

{# outputs 0, 2, 4, 6, #}

Note

ノート

Note that if the start is greater than the end, range assumes a step of -1:

開始が終了よりも大きい場合、範囲は -1 のステップを想定することに注意してください。
1
2
3
4
5
{% for i in range(3, 0) %}
    {{ i }},
{% endfor %}

{# outputs 3, 2, 1, 0, #}

The Twig built-in .. operator is just syntactic sugar for the range function (with a step of 1, or -1 if the start is greater than the end):

Twig のビルトイン .. 演算子は、rangefunction のシンタックス シュガーにすぎません (ステップ 1、または開始が終了よりも大きい場合は -1):
1
2
3
{% for i in 0..3 %}
    {{ i }},
{% endfor %}

Tip

ヒント

The range function works as the native PHP range function.

range 関数は、ネイティブの PHP range 関数として機能します。

Arguments

  • low: The first value of the sequence.
    low: シーケンスの最初の値。
  • high: The highest possible value of the sequence.
    high: シーケンスの可能な最大値。
  • step: The increment between elements of the sequence.
    step: シーケンスの要素間の増分。