Group Array By Value | ARRAY_GROUP_BY

Syntax

ARRAY_GROUP_BY( [value], [key] )

Parameters

value
The ARRAY for which the entries are being grouped. It should be an ARRAY of OBJECT / MAP records.

key
A single path or an array of paths used to select the value in each entry for grouping. If the path is an array, the items will be grouped by all the unique, ordered combinations of the values. For more information on the path syntax used by instalink.io see the dedicated documentation on that subject.

Return Value

A new ARRAY of ARRAYS where each inner ARRAY contains a group of entries in VALUE.

Description

Group the entries in ARRAY of OBJECT / MAP records according to an inner value.

Examples

ARRAY_GROUP_BY([], "a.b") # returns []
# VALUE is [["a" => 1, "b" => 2], ["a" => 2, "b" => 3], ["a" => 1, "b" => 4]]
ARRAY_GROUP_BY(VALUE, "a")
# returns [[["a" => 1, "b" => 2], ["a" => 1, "b" => 4]], [["a" => 2, "b" => 3]]]
# VALUE is [
#   ["a" => 1, "b" => 2, "c" => 3], 
#   ["a" => 2, "b" => 3, "c" => 5], 
#   ["a" => 1, "b" => 4, "c" => 4]
#   ["a" => 2, "b" => 3, "c" => 6]
# ]

ARRAY_GROUP_BY(VALUE, ["a", "b"])

# returns [
#   [
#     ["a" => 1, "b" => 2, "c" => 3], 
#   ],
#   [
#     ["a" => 2, "b" => 3, "c" => 5], 
#     ["a" => 2, "b" => 3, "c" => 6]
#   ]
#   [
#     ["a" => 1, "b" => 4, "c" => 4]
#   ]
# ]