dwo/aggregator

收集并聚合数据以进行统计分析

v1.3.3 2016-11-14 12:50 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:31:29 UTC


README

Build Status Coverage Status Scrutinizer Code Quality

Aggregator

收集、分组和聚合数据

$collector = new Collector(array('country'));
$collector->addEntry(['country' => 'DE', 'counts'=>1]);
$collector->addEntry(['country' => 'DE', 'counts'=>2]);
$collector->addEntry(['country' => 'AT', 'counts'=>2]);
$collector->addEntry(['country' => 'AT', 'counts'=>3]);

$aggregationGroup = Aggregator::aggregate($collector);

print_r($aggregationGroup->toArray());
Array (
    [DE] => Array (
        [country] => DE
        [counts] => 3
    )
    [AT] => Array (
        [country] => AT
        [counts] => 5
    )
)

合并

合并两个数组

$origin = ['counts' => 1];
$merge = ['counts' => 2];

Merger::merge($origin, $merge);

print_r($origin);
Array
(
    [counts] => 3
)