PHP code example of maciejkosiarski / easy-aggregator

1. Go to this page and download the library: Download maciejkosiarski/easy-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/ */

    

maciejkosiarski / easy-aggregator example snippets




 $array = [
    [
        'a' => 1.5,
        'b' => 2.456,
        'c' => 3,
        'd' => false,
        'e' => 'peter',
    ],
    [
        'a' => 3,
        'b' => 3.456,
        'c' => 1,
        'd' => true,
        'e' => 'john',
    ],
    [
        'a' => 1,
        'b' => 4.4567,
        'c' => 2,
        'd' => false,
        'e' => 'mark',
    ],
];
 
 $conditions = [
     'a' => '$sum',
     'b' => '$avg',
     'c' => '$max',
     'd' => '$first',
     'e' => '$last',
 ];
 
 //Are optional
 $manipulators = [
    'b' => '$round',
    'e' => '$ucfirst',
];
 
 $aggregator = new EasyAggregator();
 $aggregated = $aggregator->aggregate($array, $conditions, $manipulators);
 
 dump($aggregated);
 
 

 
 [
     'a' => 5.5,
     'b' => 3.46,
     'c' => 3,
     'd' => false,
     'e' => 'Mark',
 ];