Filter out duplicate entries in array? I have some matrix fields containing a date. I then loop through the entries in a category looking for entries containing a matrix field with a date during the next month. Everytime a matrix field is found, the entry id is added to an array of entries. Like so:

{% for event in craft.entries.section('events').type('eventWithMultipleDays').relatedTo(category).find() %}
    {% for date in event.dates if date.multiDate &gt;= now | date("Y-m-d") and date.multiDate &lt;= now | date_modify('+1 month') %}
        {# ADD THE FILTERED EVENT TO THE CATEGORYSEVENTS ARRAY #}
        {# NOTE SQUARE BRACKETS CREATE AN ARRAY - NECESSARY FOR THE MERGE #}
        {% set categoryEvents = categoryEvents | merge([event]) %}          
    {% endfor %}
{% endfor %}


Not surprisingly, some entries contain several matrix blocks with dates falling within the next month, which means the array is containing duplicate entries. That means when I output the entries array, I'm getting repetition, using this, as you'd expect:

{% for event in categoryEvents %}
    {# details output #}
{% endfor %}


Is there a way to only get unique values out of this array? Or, if not, a better way to create the array perhaps?

Thanks,
Clive
Holy moly! I've solved it already, Batman. Check the array before adding the event to it, like so:

{% if event not in categoryEvents %}
        {% set categoryEvents = categoryEvents | merge([event]) %}
{% endif %}