random

random

New in version 1.5: The random function was added in Twig 1.5.

New in version 1.6: String and integer handling was added in Twig 1.6.

The random function returns a random value depending on the supplied parameter type:

  • a random item from a sequence;
  • a random character from a string;
  • a random integer between 0 and the integer parameter (inclusive).
{{ random(['apple', 'orange', 'citrus']) }} {# example output: orange #}
{{ random('ABC') }}                         {# example output: C #}
{{ random() }}                              {# example output: 15386094 (works as the native PHP mt_rand function) #}
{{ random(5) }}                             {# example output: 3 #}

Arguments

  • values: The values

© 2009–2017 by the Twig Team
Licensed under the three clause BSD license.
The Twig logo is © 2010–2017 SensioLabs
https://twig.sensiolabs.org/doc/1.x/functions/random.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部