array_equal
Checks if two arrays contain the same elements (regardless of order). Returns true if both arrays have identical elements, false otherwise.
{% assign array_a = "apple,banana,cherry" | split: "," %}
{% assign array_b = "cherry,apple,banana" | split: "," %}
{% assign array_c = "apple,banana" | split: "," %}
{% if array_a | array_equal: array_b %}
Arrays A and B are equal
{% endif %}
{% unless array_a | array_equal: array_c %}
Arrays A and C are different
{% endunless %}Output:
Arrays A and B are equal
Arrays A and C are differentSyntax
{{ arrayA | array_equal: arrayB }}arrayA
First array
arrayB
Second array to compare
Return Value
Same elements (any order)
true
Different lengths
false
Different elements
false
Either input not an array
Error
Examples
Verify tag synchronization:
Check if permissions unchanged:
Validate order contents:
Compare collection contents:
Detect configuration changes:
Conditional processing based on array state:
Important Notes on Comparison
Order does not matter:
Duplicates matter:
Type matters (strict equality):
Notes
Both inputs must be arrays; throws error otherwise
Comparison is order-independent (set equality)
Uses strict equality (===) for element comparison
Arrays with different lengths are immediately
false(fast path)For order-sensitive comparison, convert to strings:
arrayA | join: "," == arrayB | join: ","See also:
array_difference,array_intersection,array_symmetric_difference
Last updated