Twig

灵活、快速且安全
PHP 模板引擎

a Symfony Product
文档 Filters column
您正在阅读 Twig 3.x 的文档。切换到 Twig 1.x, 2.x 的文档。

问题与反馈

许可

Twig 文档 在新的 BSD 许可 下获得许可。

column

column 过滤器从输入数组中的单列返回数值。

1
2
3
4
5
{% set items = [{ 'fruit' : 'apple'}, {'fruit' : 'orange' }] %}

{% set fruits = items|column('fruit') %}

{# fruits now contains ['apple', 'orange'] #}

注意

在内部,Twig 使用 PHP 的 array_column 函数。

参数

  • name: 要提取的列名