Download the PHP package arsalanthange/php-collections without Composer
On this page you can find all versions of the php package arsalanthange/php-collections. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arsalanthange/php-collections
More information about arsalanthange/php-collections
Files in arsalanthange/php-collections
Package php-collections
Short Description A simple PHP collection class that makes your life easier to work with arrays. Inspired from Laravel Collections.
License MIT
Informations about the package php-collections
About PHP Collections
This library converts your arrays into Collections. It comes with various built in functions to manipulate and work with arrays. The class is immutable, meaning every Collection method you execute will return an entirely new Collection instance.
Usage
Converting Array into Collection
Sorting the Collection
Paginate the Collection
Note: This method does not return a Collection
instance.
The paginate
method accepts 2 parameters.
If you require elements on the next page simply increment the page value.
Note: The paginate
method should run on the initial collection for page increments and not on the newly returned instance.
Filter the Collection
Filtering works on all the basic operations such as =
, !=
, >
, <
, >=
and <=
.
You can chain the where
method to apply multiple filters.
Count the number of elements in the Collection
Reset Array keys
The values
method resets your array keys.
Get value of a specified key
The get
method returns the value of the specified key. Returns null
if the key does not exist and if no default value is specified.
Sum elements in the collection
Average elements in the collection
Join elements in the collection into a string
If you wish to specify the glue
for implode you can pass the value in implode
method.
If the collection contains arrays or objects, you must pass the key
of the attributes you wish to join, and the glue
you wish to place between the values.