Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``column`` |
| 2 | ========== |
| 3 | |
| 4 | The ``column`` filter returns the values from a single column in the input |
| 5 | array. |
| 6 | |
| 7 | .. code-block:: twig |
| 8 | |
| 9 | {% set items = [{ 'fruit' : 'apple'}, {'fruit' : 'orange' }] %} |
| 10 | |
| 11 | {% set fruits = items|column('fruit') %} |
| 12 | |
| 13 | {# fruits now contains ['apple', 'orange'] #} |
| 14 | |
| 15 | .. note:: |
| 16 | |
| 17 | Internally, Twig uses the PHP `array_column`_ function. |
| 18 | |
| 19 | Arguments |
| 20 | --------- |
| 21 | |
| 22 | * ``name``: The column name to extract |
| 23 | |
| 24 | .. _`array_column`: https://secure.php.net/array_column |