{"id":20916189,"url":"https://github.com/yannoff/collections","last_synced_at":"2026-05-21T04:36:54.879Z","repository":{"id":57086003,"uuid":"189447195","full_name":"yannoff/collections","owner":"yannoff","description":"A simple object implementation for PHP arrays","archived":false,"fork":false,"pushed_at":"2025-12-19T19:41:34.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-31T22:42:58.539Z","etag":null,"topics":["array","collection","collections","list","map","oop","php"],"latest_commit_sha":null,"homepage":null,"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/yannoff.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-05-30T16:29:42.000Z","updated_at":"2025-12-19T19:39:13.000Z","dependencies_parsed_at":"2022-08-25T00:50:38.191Z","dependency_job_id":null,"html_url":"https://github.com/yannoff/collections","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/yannoff/collections","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannoff%2Fcollections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannoff%2Fcollections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannoff%2Fcollections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannoff%2Fcollections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yannoff","download_url":"https://codeload.github.com/yannoff/collections/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannoff%2Fcollections/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33288911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T02:57:32.698Z","status":"ssl_error","status_checked_at":"2026-05-21T02:57:31.990Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["array","collection","collections","list","map","oop","php"],"created_at":"2024-11-18T16:20:22.615Z","updated_at":"2026-05-21T04:36:54.825Z","avatar_url":"https://github.com/yannoff.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yannoff/collections\n\nA simple object implementation of PHP arrays.\n\n[![Latest Stable Version](https://poser.pugx.org/yannoff/collections/v/stable)](https://packagist.org/packages/yannoff/collections)\n[![Total Downloads](https://poser.pugx.org/yannoff/collections/downloads)](https://packagist.org/packages/yannoff/collections)\n[![License](https://poser.pugx.org/yannoff/collections/license)](https://packagist.org/packages/yannoff/collections)\n\n## The concept\n\nBased upon the Decorator design pattern, the aim is to provide a flexible, object-oriented alternative to PHP Arrays.\n\n## Installation\n\nUsing [composer](https://getcomposer.org/):\n\n```bash\n$ composer require yannoff/collections\n```\n\n## Usage\n\nExample: PHP Array vs Collection\n\n_The classic way - native PHP arrays:_\n\n```php\n\u003c?php\n\n// Using PHP native arrays, the classic way:\n$countries = [ 'France', 'Italia' ];\n\n// Push an element\narray_push($countries, 'Switzerland');\n\n// Append an element\n$countries[] = 'Belgium';\n\n```\n\n_The new way - using collections:_\n\n```php\n\u003c?php\n\nuse Yannoff\\Component\\Collections\\Collection;\n\n// Using collections:\n$countries = new Collection([ 'France', 'Italia' ]);\n\n// Push an element\n$countries-\u003epush('Switzerland');\n\n// Append an element: the same syntax as for arrays\n$countries[] = 'Belgium';\n\n// Exporting the collection back to a native PHP array:\n$array = $countries-\u003eall();\n\n// As for native arrays, collections can be traversed with a foreach:\nforeach($countries as $key =\u003e $value) {\n    // ...\n}\n\n```\n\n### Methods \n\n_See the [full method list](/doc/api/Collection.md) for more details._\n\nArray / Collection method equivalences:\n\n|Array|Collection|\n|-----|----------|\n|implode($glue, $array)|$collection-\u003ejoin($glue)|\n|array_filter($array, $callback, $flag)|$collection-\u003efilter($callback, $flag)|\n|array_flip($array)|$collection-\u003eflip()|\n|array_keys($array)|$collection-\u003ekeys()|\n|array_map($callback, $array, ..$arrays)|$collection-\u003emap($callback, ...$arrays)|\n|array_pop(\u0026$array)|$collection-\u003epop()|\n|array_push(\u0026$array, $element)|$collection-\u003epush($element)|\n|array_reverse($array)|$collection-\u003ereverse()|\n|array_search($needle, $array)|$collection-\u003esearch($needle)|\n|array_slice($array, $offset, $length)|$collection-\u003eslice($offset, $length)|\n|array_shift(\u0026$array)|$collection-\u003eshift()|\n|array_unique($array, $flags)|$collection-\u003eunique($flags)|\n|array_unshift(\u0026$array, $element)|$collection-\u003eunshift($element)|\n|array_walk(\u0026$array, $callback, $userdata)|$collection-\u003ewalk($callback, $userdata)|\n|explode($separator, $strint, $limit)|Collection::explode($separator, $strint, $limit)|\n|current(\u0026$array)|$collection-\u003ecurrent()|\n|end(\u0026$array)|$collection-\u003eend()|\n|next(\u0026$array)|$collection-\u003enext()|\n|prev(\u0026$array)|$collection-\u003eprev()|\n|sort(\u0026$array)|$collection-\u003esort()|\n|asort(\u0026$array)|$collection-\u003easort()|\n|ksort(\u0026$array)|$collection-\u003eksort()|\n\nAlong with those classical PHP methods wrappers, a few _bag_ methods are provided:\n\n|method|description|\n|------|-----------|\n|add($key, $element)|Add an element at the given key in the collection|\n|all()|Return all the collection elements|\n|clear()|Remove all elements from the collection|\n|get($key)|Get an element of the collection by its key|\n|has($key)|Check for existence of the given key in the collection|\n|set($elements)|Set the whole elements of the collection|\n\n\n\n## License\n\nReleased under the [MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannoff%2Fcollections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyannoff%2Fcollections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannoff%2Fcollections/lists"}