francerz/php-power-data 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

francerz/php-power-data

最新稳定版本:v0.1.39

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, ...$_)

统计信息

  • 总下载量: 2.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-10-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固