多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# `range` Returns a list containing an arithmetic progression of integers: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3 4 5</pre></div></td><td class="code"><div class="highlight"><pre>{% for i in range(0, 3) %} {{ i }}, {% endfor %} {# outputs 0, 1, 2, 3, #} </pre></div></td></tr></table> When step is given (as the third parameter), it specifies the increment (ordecrement): <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3 4 5</pre></div></td><td class="code"><div class="highlight"><pre>{% for i in range(0, 6, 2) %} {{ i }}, {% endfor %} {# outputs 0, 2, 4, 6, #} </pre></div></td></tr></table> The Twig built-in `..` operator is just syntactic sugar for the `range`function (with a step of 1): <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2 3</pre></div></td><td class="code"><div class="highlight"><pre>{% for i in 0..3 %} {{ i }}, {% endfor %} </pre></div></td></tr></table> Tip The `range` function works as the native PHP [range](http://php.net/range) [http://php.net/range] function. ### Arguments - `low`: The first value of the sequence. - `high`: The highest possible value of the sequence. - `step`: The increment between elements of the sequence.