https://github.com/ghostwriter/collection
Provides a Collection implementation for PHP
https://github.com/ghostwriter/collection
Last synced: 2 months ago
JSON representation
Provides a Collection implementation for PHP
- Host: GitHub
- URL: https://github.com/ghostwriter/collection
- Owner: ghostwriter
- License: other
- Created: 2022-06-22T05:22:25.000Z (almost 4 years ago)
- Default Branch: 2.0.x
- Last Pushed: 2025-04-22T00:45:01.000Z (about 1 year ago)
- Last Synced: 2025-04-22T01:29:19.305Z (about 1 year ago)
- Language: PHP
- Size: 672 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Collection
[](https://github.com/sponsors/ghostwriter)
[](https://github.com/ghostwriter/collection/actions/workflows/automation.yml)
[](https://www.php.net/supported-versions)
[](https://packagist.org/packages/ghostwriter/collection)
Provides a Collection implementation for PHP.
## Installation
You can install the package via composer:
``` bash
composer require ghostwriter/collection
```
### Star ⭐️ this repo if you find it useful
You can also star (🌟) this repo to find it easier later.
## Usage
```php
/** @var \Ghostwriter\Collection\Collection $collection */
$collection = Collection::new([1, 2, 3])
->append([4, 5, 6, 7, 8, 9])
->map(static fn ($v): int => $v * 10)
->filter(static fn ($v): bool => 0 === $v % 20);
$collection->toArray(); // [20, 40, 60, 80]
$collection->drop(1) // [40, 60, 80]
->take(2) // [40, 60]
->slice(1, 1) // [60]
->toArray(); // [60]
```
### Credits
- [Nathanael Esayeas](https://github.com/ghostwriter)
- [All Contributors](https://github.com/ghostwriter/collection/contributors)
## Thank you
Thank you for freely sharing your knowledge, insight and free time with me. I am grateful for your help and support.
- [Larry Garfield](https://github.com/crell)
- [Aleksei Khudiakov](https://github.com/xerkus)
- [Andi Rückauer](https://github.com/arueckauer)
### Changelog
Please see [CHANGELOG.md](./CHANGELOG.md) for more information on what has changed recently.
### License
Please see [LICENSE](./LICENSE) for more information on the license that applies to this project.
### Security
Please see [SECURITY.md](./SECURITY.md) for more information on security disclosure process.