{"id":15046080,"url":"https://github.com/jakezatecky/array_group_by","last_synced_at":"2025-10-25T20:35:54.647Z","repository":{"id":17077477,"uuid":"19842480","full_name":"jakezatecky/array_group_by","owner":"jakezatecky","description":"A PHP function that groups an array by a key or set of keys shared between all array members.","archived":false,"fork":false,"pushed_at":"2023-03-23T23:15:42.000Z","size":55,"stargazers_count":99,"open_issues_count":1,"forks_count":17,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-30T14:11:26.039Z","etag":null,"topics":["composer","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakezatecky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2014-05-16T02:39:42.000Z","updated_at":"2024-12-14T18:38:18.000Z","dependencies_parsed_at":"2024-06-18T16:40:08.056Z","dependency_job_id":null,"html_url":"https://github.com/jakezatecky/array_group_by","commit_stats":{"total_commits":89,"total_committers":4,"mean_commits":22.25,"dds":0.101123595505618,"last_synced_commit":"c470211aec034ba7d7c475c50ec344be147bcd7c"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakezatecky%2Farray_group_by","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakezatecky%2Farray_group_by/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakezatecky%2Farray_group_by/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakezatecky%2Farray_group_by/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakezatecky","download_url":"https://codeload.github.com/jakezatecky/array_group_by/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509236,"owners_count":20950232,"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":["composer","php"],"created_at":"2024-09-24T20:52:40.868Z","updated_at":"2025-10-25T20:35:54.632Z","avatar_url":"https://github.com/jakezatecky.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# array_group_by\n\n[![Packagist](https://img.shields.io/packagist/v/jakezatecky/array_group_by.svg?style=flat-square)](https://packagist.org/packages/jakezatecky/array_group_by)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/jakezatecky/array_group_by/main.yml?branch=main\u0026style=flat-square)](https://github.com/jakezatecky/array_group_by/actions/workflows/main.yml)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/jakezatecky/array_group_by/master/LICENSE.txt)\n\n\u003e A PHP function to group an array by a key or set of keys shared between all array members.\n\n## Installation\n\nTo get the latest version of `array_group_by`, simply require the project using Composer:\n\n``` shell\n$ composer require jakezatecky/array_group_by\n```\n\nNeed support for PHP 5.6? Then run the following:\n\n``` shell\n$ composer require jakezatecky/array_group_by:^1.1.0\n```\n\nIf you do not want to use Composer, you can just `require` the `src/array_group_by.php` file.\n\n## Usage\n\nTo use `array_group_by`, simply pass an array with any number of keys to group by:\n\n``` php\n$records = [\n    [\n        'state'  =\u003e 'IN',\n        'city'   =\u003e 'Indianapolis',\n        'object' =\u003e 'School bus',\n    ],\n    [\n        'state'  =\u003e 'IN',\n        'city'   =\u003e 'Indianapolis',\n        'object' =\u003e 'Manhole',\n    ],\n    [\n        'state'  =\u003e 'IN',\n        'city'   =\u003e 'Plainfield',\n        'object' =\u003e 'Basketball',\n    ],\n    [\n        'state'  =\u003e 'CA',\n        'city'   =\u003e 'San Diego',\n        'object' =\u003e 'Light bulb',\n    ],\n    [\n        'state'  =\u003e 'CA',\n        'city'   =\u003e 'Mountain View',\n        'object' =\u003e 'Space pen',\n    ],\n];\n\n$grouped = array_group_by($records, 'state', 'city');\n```\n\nExample output:\n\n``` text\nArray\n(\n    [IN] =\u003e Array\n        (\n            [Indianapolis] =\u003e Array\n                (\n                    [0] =\u003e Array\n                        (\n                            [state] =\u003e IN\n                            [city] =\u003e Indianapolis\n                            [object] =\u003e School bus\n                        )\n\n                    [1] =\u003e Array\n                        (\n                            [state] =\u003e IN\n                            [city] =\u003e Indianapolis\n                            [object] =\u003e Manhole\n                        )\n\n                )\n\n            [Plainfield] =\u003e Array\n                (\n                    [0] =\u003e Array\n                        (\n                            [state] =\u003e IN\n                            [city] =\u003e Plainfield\n                            [object] =\u003e Basketball\n                        )\n\n                )\n\n        )\n\n    [CA] =\u003e Array\n        (\n            [San Diego] =\u003e Array\n                (\n                    [0] =\u003e Array\n                        (\n                            [state] =\u003e CA\n                            [city] =\u003e San Diego\n                            [object] =\u003e Light bulb\n                        )\n\n                )\n\n            [Mountain View] =\u003e Array\n                (\n                    [0] =\u003e Array\n                        (\n                            [state] =\u003e CA\n                            [city] =\u003e Mountain View\n                            [object] =\u003e Space pen\n                        )\n\n                )\n\n        )\n)\n```\n\n### Using a Callback\n\nIf more complex grouping behavior is desired, you can also pass in a callback function to determine the group key:\n\n``` php\n$grouped = array_group_by($records, function ($row) {\n    return $row-\u003ecity;\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakezatecky%2Farray_group_by","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakezatecky%2Farray_group_by","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakezatecky%2Farray_group_by/lists"}