dev-master
9999999-devProvides a set of methods for querying objects.
MIT
The Requires
- php >=7.1
The Development Requires
by Mathias STRASSER
Provides a set of methods for querying objects.
Provides a set of methods for querying objects.
Enumerable is a collection library for PHP >= 7.1 that implements most of the sequence operations proposed by collection pipeline object methods., (*1)
Require this package using Composer., (*2)
composer require roukmoute/enumerable
, (*3)
Here is a catalog of the operations that you often find in collection pipelines :, (*4)
, (*5)
Runs a boolean function on each element and only puts those that pass into the output., (*6)
You can use this function to keep only the items of the input you want to work
with.
For example:, (*7)
$query = (new \Enumerable\Enumerable([0, 30, 20, 15, 90, 85, 40, 75]))->filter( function ($number, $index) { return $number <= $index * 10; } ); foreach ($query as $number) { echo $number . PHP_EOL; } /* This code produces the following output: 0 20 15 40 */
, (*8)
Concatenates collections into a single collection, (*9)
$query = (new \Enumerable\Enumerable([1, 2, 3]))->concat([4, 5]); foreach ($query as $name) { echo $name . PHP_EOL; } // This code produces the following output: // // 1 // 2 // 3 // 4 // 5
If you want to concatenate more than two collections :, (*10)
$query = (new \Enumerable\Enumerable([1, 2, 3]))->concat([4, 5])->concat([6]); foreach ($query as $name) { echo $name . PHP_EOL; } // This code produces the following output: // // 1 // 2 // 3 // 4 // 5 // 6
, (*11)
Remove the contents of the supplied list from the pipeline, (*12)
$query = (new \Enumerable\Enumerable([1, 1, 2, 2, 3, 4]))->difference([1, 3]); foreach ($query as $number) { echo $number . PHP_EOL; } // This code produces the following output: // // 2 // 2 // 4
, (*13)
Removes duplicate elements, (*14)
Returns a new list with any duplicates removed., (*15)
$query = (new \Enumerable\Enumerable([1, 2, 3, 2, 1]))->distinct(); foreach ($query as $number) { echo $number . PHP_EOL; } // This code produces the following output: // // 1 // 2 // 3
, (*16)
Return a sub-sequence of the list between the given first and last positions., (*17)
If you want some of the list, you can take a slice of the list., (*18)
$query = (new \Enumerable\Enumerable([1, 2, 3, 4, 5, 6]))->slice(2, 4); foreach ($query as $number) { echo $number . PHP_EOL; } /** * This code produces the following output: * * 3 * 4 * 5 */
Provides a set of methods for querying objects.
MIT