{"id":21688445,"url":"https://github.com/micheledurante/array-aggregate","last_synced_at":"2025-03-20T12:27:31.413Z","repository":{"id":57017004,"uuid":"188892902","full_name":"micheledurante/array-aggregate","owner":"micheledurante","description":"A PHP, SQL-like stream aggregate function to group a set of rows by any number of columns. You can also define how to compute groups","archived":false,"fork":false,"pushed_at":"2023-07-05T08:54:26.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-25T12:41:28.550Z","etag":null,"topics":["array-function","php","stream-aggregate"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/micheledurante.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-27T18:39:13.000Z","updated_at":"2023-07-07T19:30:44.000Z","dependencies_parsed_at":"2025-01-25T12:40:30.082Z","dependency_job_id":"ad0f0864-f8f3-4ae2-86bd-0e3982d2e543","html_url":"https://github.com/micheledurante/array-aggregate","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheledurante%2Farray-aggregate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheledurante%2Farray-aggregate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheledurante%2Farray-aggregate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheledurante%2Farray-aggregate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micheledurante","download_url":"https://codeload.github.com/micheledurante/array-aggregate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244610653,"owners_count":20481031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array-function","php","stream-aggregate"],"created_at":"2024-11-25T17:15:07.701Z","updated_at":"2025-03-20T12:27:31.373Z","avatar_url":"https://github.com/micheledurante.png","language":"PHP","readme":"# array_aggregate\n[![Build Status](https://travis-ci.org/micheledurante/array-aggregate.svg?branch=master)](https://travis-ci.org/micheledurante/array-aggregate)\n[![Latest Stable Version](https://img.shields.io/packagist/php-v/micheledurante/array-aggregate.svg)](https://packagist.org/packages/micheledurante/array-aggregate)\n[![Latest Stable Version](https://img.shields.io/packagist/v/micheledurante/array-aggregate.svg)](https://packagist.org/packages/micheledurante/array-aggregate)\n\nA PHP, SQL-like stream aggregate function to group a set of rows by any number of columns. You can also define how to \ncompute groups. Rows are expected to be already sorted on the columns used to aggregate results.\n\n```php\nfunction array_aggregate(array $columns, array $rows, callable $compute_func = null): array\n```\n\nThe order in which columns are given to the function does not affect the output. Columns must comparable with the `===` \noperator.\n\nInspired by Craig Freedman's SQL articles on MS dev blog \nhttps://blogs.msdn.microsoft.com/craigfr/2006/09/13/stream-aggregate.\n\n## Installation\n\nAs a composer package:\n```\ncomposer require micheledurante/array-aggregate\n```\n\nOr require the source file in `src/array_aggregate.php`.\n\n## Usage\n\n```php\n$rows = [\n    0 =\u003e [\n        'store_id' =\u003e 1,\n        'manager_id' =\u003e 2,\n        'name' =\u003e 'Alice'\n    ],\n    1 =\u003e [\n        'store_id' =\u003e 2,\n        'manager_id' =\u003e 3,\n        'name' =\u003e 'Bob'\n    ],\n    2 =\u003e [\n        'store_id' =\u003e 2,\n        'manager_id' =\u003e 3,\n        'name' =\u003e 'Eve'\n    ],\n    3 =\u003e [\n        'store_id' =\u003e 2,\n        'manager_id' =\u003e 4,\n        'name' =\u003e 'Foobar'\n    ]\n];\n\n$groups = array_aggregate(array('store_id', 'manager_id'), $rows, function (array $group): array {\n    return [\n        'store_id' =\u003e $group[0]['store_id'],\n        'manager_id' =\u003e $group[0]['manager_id'],\n        'people' =\u003e implode(',', array_column($group, 'name'))\n    ];\n});\n\nvar_export($groups);\n```\n\nResults in:\n```php\n/*\narray (\n    0 =\u003e array (\n        'store_id' =\u003e 1,\n        'manager_id' =\u003e 2,\n        'people' =\u003e 'Alice'\n    ),\n    1 =\u003e array (\n        'store_id' =\u003e 2,\n        'manager_id' =\u003e 3,\n        'people' =\u003e 'Bob,Eve'\n    ),\n    2 =\u003e array (\n        'store_id' =\u003e 2,\n        'manager_id' =\u003e 4,\n        'people' =\u003e 'Foobar'\n    )\n)\n*/\n```\n\n## Similar Projects\n\n### `array_group_by()`\nBy [jakezatecky](https://github.com/jakezatecky/array_group_by). Main difference is that \n`array_aggregate()` won't change the structure of the array by creating new keys/nested groups. It behaves like the SQL \n`GROUP BY` clause, which returns the aggregates of the input rows. Both functions can work with multiple keys. \n`array_aggregate()` doesn't allow a callable to match columns.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicheledurante%2Farray-aggregate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicheledurante%2Farray-aggregate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicheledurante%2Farray-aggregate/lists"}