Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``last`` |
| 2 | ======== |
| 3 | |
| 4 | The ``last`` filter returns the last "element" of a sequence, a mapping, or |
| 5 | a string: |
| 6 | |
| 7 | .. code-block:: twig |
| 8 | |
| 9 | {{ [1, 2, 3, 4]|last }} |
| 10 | {# outputs 4 #} |
| 11 | |
| 12 | {{ { a: 1, b: 2, c: 3, d: 4 }|last }} |
| 13 | {# outputs 4 #} |
| 14 | |
| 15 | {{ '1234'|last }} |
| 16 | {# outputs 4 #} |
| 17 | |
| 18 | .. note:: |
| 19 | |
| 20 | It also works with objects implementing the `Traversable`_ interface. |
| 21 | |
| 22 | .. _`Traversable`: https://secure.php.net/manual/en/class.traversable.php |