Skip to content Skip to footer navigation
You are reading the docs for an old version of Statamic. Consider upgrading to Statamic 6.

In Array Modifier

Check if an array contains a specific value. Returns true if a match is found.

The first parameter is the "needle" to find in the "haystack". It will read from the context if there is a matching variable, otherwise it will use the parameter as the value. You can pass multiple arguments.

shopping_list:
- eggs
- flour
- beef jerky
want: eggs
{{ if (shopping_list | in_array('flour')) }} GOT IT! {{ /if }}
{{ if (shopping_list | in_array('want')) }} GOT EM! {{ /if }}
{{ if (shopping_list | in_array('eggs', 'flour')) }} YES I DID NOT FORGET! {{ /if }}
@if (Statamic::modify($shopping_list)->inArray('flour')->fetch()) GOT IT! @endif
@if (Statamic::modify($shopping_list)->inArray('want')->fetch()) GOT EM! @endif
@if (Statamic::modify($shopping_list)->inArray('eggs', 'flour')->fetch()) YES I DID NOT FORGET! @endif
GOT IT!
GOT EM!
YES I DID NOT FORGET!