我在树枝中有一个名为“Posts”的数组。
有没有办法轻松删除该数组的第一项?
所以它的结构就像这样:
array('post 1','post 2','post 3')
我想知道是否可以使用 twig 中的函数轻松删除第一篇文章:
array('post 2','post 3')
您正在寻找slice https://twig.symfony.com/doc/3.x/filters/slice.html filter.
切片过滤器提取序列、映射或字符串的切片:
{% for i in ['post 1', 'post 2', 'post 3'] | slice(1) %}
{{ i }}
{% endfor %}
output
post 2
post 3
The slice https://twig.symfony.com/doc/3.x/filters/slice.html过滤器的工作原理是数组切片 https://www.php.net/manual/en/function.array-slice.php用于数组和的 PHP 函数mb_substr https://www.php.net/manual/en/function.mb-substr对于回退到的字符串substr https://www.php.net/manual/en/function.substr.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)