1. Go to this page and download the library: Download francerz/php-power-data 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/ */
francerz / php-power-data example snippets
use Francerz\PowerData\Index;
$index = new Index($data, ['column1', 'column2']);
$col1Values = $index->getColumnValues('column1');
$col2Values = $index->getColumnValues('column2');
foreach ($col1Values as $c1) {
foreach ($col2Values as $c2) {
// Retrieves all items that matches $c1 and $c2.
$items = $index[['column1' => $c1, 'column2' => $c2]];
$numItems = $index->xCount(['column1' => $c1, 'column2' => $c2]);
$sumCol3 = $index->sum('column3', ['column1' => $c1, 'column2' => $c2]);
$first = $index->first(['column1' => $c1, 'column2' => $c2]);
$last = $index->last(['column1' => $c1, 'column2' => $c2]);
}
// Retrieves all items that matches $c1
$items = $index[['column1' => $c1]];
}
$index = new Index($data, ['country', 'city']);
// Group by a single column
$groupedByCity = $index->groupBy('city');
// Group by multiple columns
$groupedByCountryAndCity = $index->groupBy(['country', 'city']);
print_r($groupedByCity);