Twig :: zip

The zip filter allows you to concat each of the elements in two arrays together with a specified glue.

Since

0.1.2

Usage

zip(arr, glue = "", strict = false)

Parameters

  • (required) arr : array

    The second array we'll be zipping together.

  • glue : string

    The character(s) used to "zip" the two values together.

  • strict : bool

    When set to true, only the amount of elements of the shortest array will be used. Any extra elements on either array will not be zipped together.

Example Usage

{% set array_1 = ['hello', "it's", 'to', 'you'] %}
{% set array_2 = ['world', 'nice', 'meet'] %}

<!-- ['hello world', "it's nice", 'to meet', 'you'] -->
{{ array_1 | zip(array_2, ' ') }}

<!-- ['hello world', "it's nice", 'to meet'] -->
{{ array_1 | zip(array_2, ' ', true) }}