PHP code example of dwo / aggregator

1. Go to this page and download the library: Download dwo/aggregator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dwo / aggregator example snippets


$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
)