Download the PHP package hyqo/collection without Composer
On this page you can find all versions of the php package hyqo/collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package collection
collection
Basic collection with Generics support
Install
Usage
For example, we have a Product class that we want to wrap in a collection:
Create a collection:
Auto-completion
There are three ways for code auto-completion:
1. Create a collection with items (not empty):
2. Use PHPDoc with Generics annotation:
3. Use your own class with @extends annotation:
Now you have auto-completion (see the picture above)
Methods
add
Add new item to a collection:
get
Get item of a collection by index:
each
Pass each item to a closure:
map
Pass each item to a closure and create a new collection of results.
The closure must return a value of T or \Generator<T>:
reduce
Reduces the collection to a single value:
slice
Create a new collection with a slice of the current one:
copy
Create a new collection with the same elements (alias for slice(0)):
chunk
Breaks the collection into multiple collections of a given length. The last one may contain fewer elements:
filter
Pass each item to a closure and create a new collection of items for which its result will be true.
The closure must return a bool value:
toArray
Return all items of a collection. You can transform every element of array via a closure. If you need an associative array, the closure should return a generator yielding a key/value pair.
The closure must return any value or \Generator<array-key,mixed>:
All versions of collection with dependencies
ext-json Version *