Download the PHP package softboxlab/php-collection-helper without Composer
On this page you can find all versions of the php package softboxlab/php-collection-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download softboxlab/php-collection-helper
More information about softboxlab/php-collection-helper
Files in softboxlab/php-collection-helper
Package php-collection-helper
Short Description Simple array and object-oriented collection
License MIT
Informations about the package php-collection-helper
Simple PHP Collection and array helper
Simple collection class to work with arrays on object-oriented paradigm and some array (collection) helpers with standardization of the parameters (data first, callback later, like javascript).
Collection
In this definition, our collection is Immutable, which means that every operation should return a new collection, keeping the original collection intact.
Collection helper
This is the base support to the Collection class. All the methods are implemented here.
List of available methods
- map($data, $callback ($value, $key));
- Map all the items of data with the provided callback. The callback will receive both value's and key's of the array.
- filter($data, $callback($value, $key), $keepKeys);
- Filter the given array with the provided callback. Only the items when the callback return's true will be returned on the filtered data. If false is passed to keepKeys parameter, the keys will be reseted.
- reduce($data, $callback($value, $key), $initialValue);
- Reduce's the given data with the given callback.
- transform($data, $changes, $delimiter);
- Transform the keys (change) of the given
$data
array with the$changes
array. To navigate along the array, use the Laravel's dot syntax. If$delimiter
provided, it changed the Laravel's dot syntax separator.
- Transform the keys (change) of the given
- transformArray($data, $changed, $delimiter);
- Same as transform, but should be used on a list, which will apply on every item. Same as map with transform.
Transformer class
Simple array transformer class, which convert all the keys by new ones. Something like a from-to
where the all the keys of the given array will be replaced the by the value of the given replaced array when the key matches.
Example:
Contributing
Feel free to make any pull request you judge necessary!