{"id":31908311,"url":"https://github.com/enzyme/collection","last_synced_at":"2025-10-13T15:26:58.494Z","repository":{"id":56978269,"uuid":"59178796","full_name":"enzyme/collection","owner":"enzyme","description":"An all encompassing array manager.","archived":false,"fork":false,"pushed_at":"2016-10-11T23:24:30.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-31T11:52:57.114Z","etag":null,"topics":[],"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/enzyme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-19T06:12:01.000Z","updated_at":"2016-07-08T20:41:36.000Z","dependencies_parsed_at":"2022-08-21T08:10:54.763Z","dependency_job_id":null,"html_url":"https://github.com/enzyme/collection","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/enzyme/collection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fcollection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fcollection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fcollection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fcollection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enzyme","download_url":"https://codeload.github.com/enzyme/collection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fcollection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015919,"owners_count":26085778,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-10-13T15:26:51.257Z","updated_at":"2025-10-13T15:26:58.489Z","avatar_url":"https://github.com/enzyme.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Collection\n[![Build Status](https://travis-ci.org/enzyme/collection.svg?branch=master)](https://travis-ci.org/enzyme/collection)\n[![Coverage Status](https://coveralls.io/repos/github/enzyme/collection/badge.svg?branch=develop)](https://coveralls.io/github/enzyme/collection?branch=develop)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/enzyme/collection/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/enzyme/collection/?branch=master)\n[![StyleCI](https://styleci.io/repos/59178796/shield)](https://styleci.io/repos/59178796)\n\nAn all encompassing array manager.\n\n# Installation\n\n```bash\n$ composer require enzyme/collection\n```\n\n# Usage\n\nYou can create a collection from a standard PHP array. Once you have a collection, you can make use of all the methods it exposes.\n\n```php\nuse Acme\\Mailer;\nuse Enzyme\\Collection\\Collection;\n\n$users = new Collection(['John123', 'Jane456', 'Harry789']);\n\n// Send each user an email.\n$users-\u003eeach(function ($user) {\n    Mailer::sendWelcomeEmail($user);\n});\n```\n\nThe collection implements `ArrayAccess`, `Iterator` and `Countable`, so you can use it as a standard array.\n\n```php\nuse Enzyme\\Collection\\Collection;\n\n$users = new Collection(['John123', 'Jane456', 'Harry789']);\n\nvar_dump($users[0]); // 'John123'\n```\n\nIn the example above, the equivalent and much more readable method would be `$collection-\u003efirst()`.\n\n# Available methods\n\n| Method signature | Description |\n| ---: | :--- |\n| `count()` | Return the number of elements in the collection. |\n| `each(Closure $fn)` | Execute the callback function provided on each item in the collection. The callback function is passed `$value, $key` as arguments. If the callback returns `false`, the function will return early and will not continue iterating over the remaining items left in the collection.|\n| `except(array $keys)` | Return a new collection containing all the keys in the current collection except those whose keys match the ones provided. |\n| `filter(Closure $fn)` | Return a new collection will all items that pass the given callback functions truth test. |\n| `first()` | Get the value of the first item in the collection. If the collection is empty, a `CollectionException` will be thrown. |\n| `firstOrDefault($default = null)` | Same as above, except instead of throwing an exception, return the provided default value. |\n| `get($key)` | Get the value associated with the specified key. If the key does not exist, a `CollectionException` will be thrown. |\n| `getOrDefault($key, $default = null)` | Same as above, except instead of throwing an exception, return the provided default value. |\n| `has($key, $value = null)` | Checks whether the collection has the specified key, and/or key/value pair. |\n| `hasCount($min, $max = null)` | Checks whether the collection has the minimum count specified, or a count that falls within the range specified. |\n| `isEmpty()` | Whether the collection is empty. |\n| `keys()` | Returns an array of all the keys used by the collection. |\n| `last()` | Get the value of the last item in the collection. If the collection is empty, a `CollectionException` will be thrown. |\n| `lastOrDefault($default = null)` | Same as above, except instead of throwing an exception, return the provided default value. |\n| `make(array $initial)` *static* | Static helper method to instantiate a new collection. Useful for when you want to immediately chain a method. Eg: Collection::make([1, 2, 3])-\u003emap(...) |\n| `map(Closure $fn)` | Execute the callback function provided on each item in the collection. The callback function is passed `$value, $key` as arguments. The return value of the callback function will be saved into a new collection and that collection will be returned as a result |\n| `mapWithKey(Closure $fn)` | Execute the given callback function for each element in this collection and save the results to a new collection with the specified key. The callback function should return a 1 element associative array, eg: ['key' =\u003e 'value'] to be mapped. |\n| `only(array $keys)` | Return a new collection containing only the items in the current collection whose keys match the ones provided. |\n| `pluck($pluck_key, $deep = true)` | Grab and return a new collection will all values that have the specified `key`. By default, this will traverse multidimensional arrays. |\n| `push($value)` | Return a new collection with the given value pushed onto a copy of the current collection's items. |\n| `pushArray(array $data)` | Return a new collection with the given array pushed onto a copy of the current collection's items. |\n| `pushWithKey($key, $value)` | Return a new collection with the given key/value pair pushed onto a copy of the current collection's items. |\n| `sort(Closure $fn)` | Return a new collection after the user defined sort function has been executed on the items. Same callback function parameters as the PHP `usort` function. |\n| `toArray()` | Returns the current collection as a standard PHP array. |\n\n# Contributing\n\nPlease see `CONTRIBUTING.md`\n\n# License\n\nMIT - Copyright (c) 2016 Tristan Strathearn, see `LICENSE`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenzyme%2Fcollection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenzyme%2Fcollection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenzyme%2Fcollection/lists"}