Get a Demo
Table of contents

last Twig Filter

The last filter returns the last element of an array, hash or string.

Array

{{ [1, 2, 3, 4]|last }}

The above will output: 4.

Hash

{{ {'name': 'Sam', 'age': 55}|last }}

String

{{ 'Bob Hope'|last }}

The above will output "e"

Assignment Link

As with all filters, you can use the last filter when assigning a variable.

{% set name = 'Bob Hope' %}
{% set letter = name|last %}
Get Started With Aptuitiv