intersect_assoc
The intersect_assoc filter returns an array containing only the values that are in both arrays. The array keys are also used in the comparison.
{% set myColors = {'g': 'green', 'b': 'blue', 'y': 'yellow', 'r': 'red'} %}
{% set yourColors = {'b': 'brown', 'g': 'green', 'x': 'yellow'} %}
{% set sameColors = myColors|intersect_assoc(yourColors) %}
{# sameColors is {'g': 'green'} #}
Arguments
The intersect_assoc filter has the following signature.
intersect_assoc(array)
Argument | Description |
---|---|
array | The array to intersect with the original value. |