francerz/php-power-data
Composer 安装命令:
composer require francerz/php-power-data
包简介
PHP data structures for complex data handling
README 文档
README
Installation
This package can be installed with composer using following command.
composer require francerz/php-power-data
Using Index class
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]]; }
Method groupBy($columns)
The groupBy method allows you to group records from an indexed dataset based
on one or more column values. The grouping is performed incrementally, meaning
that the method applies filters progressively on the existing index to avoid
unnecesary memory and processing overhead. This ensures that the performance
remains efficient, even with large datasets.
Parameters:
$columns(string|array): The name of a single column (string) or an array of column names (array) by which the data should be grouped. The method will return a nested grouping if multiple columns are provided.
Returns:
- array: Returns a nested associative array, where each key corresponds to the unique values in the specified columns. The innermost arrays contain the records that match teh specific grouping of column values.
How it works:
The methods does not create a new index fore each group. Instead, progressively filters the data of each column's unique values, grouping the results step by step. This approach reduces memory consumption and processing time by avoiding redundant operations on the dataset.
Example Usage:
$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);
Aggregations
Aggregations::concat(array $values, $separator = '') Aggregations::count(array $values, bool $ignoreNulls = false) Aggregations::findPercentile(array $values, float $value, int $flags = self::PERCENTILE_FLAGS_MIDDLE) Aggregations::first(array $values) Aggregations::frequencies(array $values) Aggregations::last(array $values) Aggregations::max(array $values) Aggregations::mean(array $values, bool $ignoreNulls = false) Aggregations::median(array $values) Aggregations::min(array $values) Aggregations::mode(array $values, bool $strict = false) Aggregations::percentile(array $values, float $percentile, int $flags = self::PERCENTILE_FLAGS_MIDDLE) Aggregations::product(array $values, bool $ignoreEmpty = false) Aggregations::sum(array $values)
Arrays
Arrays::hasNumericKeys(array $array) Arrays::hasStringKeys(array $array) Arrays::findKeys(array $array, string $pattern) Arrays::remove(array &$array, $value) Arrays::filter($array, $callback = null, $flag = 0) Arrays::intersect(array $array1, array $array2, ...$_)
francerz/php-power-data 适用场景与选型建议
francerz/php-power-data 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 francerz/php-power-data 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 francerz/php-power-data 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2020-10-05