ArrayMerge
Merges an array of objects
Table of Contents
Methods
| combineSum() | Merges all objects in the array with the given shared property $id into a single object, and summing the value of the shared property $key |
Methods
combineSum()
Merges all objects in the array with the given shared property $id into a single object, and summing the value of the shared property $key
public
combineSum(array<string|int, mixed> $data, string $id, string $key) : A
Parameters
- $data : array<string|int, mixed>
-
An array of objects to combine
- $id : string
-
The name of an object's property to use as the unique identifier for duplicates. The value of this property must be valid keys (integer or string)
- $key : string
-
The name of the object's property whose value to combine by summing duplicates. The value of this property should be a float
Return values
A —subset array of objects with duplicate object $id's combined