Download the PHP package fusonic/linq without Composer
On this page you can find all versions of the php package fusonic/linq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package linq
Short Description LINQ 2 objects class for PHP
License MIT
Homepage http://fusonic.github.io/fusonic-linq/
Informations about the package linq
Project discontinued!
Development and maintenance of
fusonic/linq
is discontinued since there are more popular options available. We recommend to useilluminate/collections
(docs, GitHub) in new projects. Feel free to use existing versions and/or forkfusonic/linq
for your own needs.
fusonic/linq
fusonic/linq is a lightweight PHP library inspired by the LINQ 2 Objects extension methods in .NET.
For a full introduction read my blog-post: http://www.fusonic.net/en/blog/2013/08/14/fusonic-linq-write-less-do-more/
LINQ queries offer three main advantages over traditional foreach loops:
-
They are more concise and readable, especially when filtering multiple conditions.
-
They provide powerful filtering, ordering, and grouping capabilities with a minimum of application code.
- In general, the more complex the operation you want to perform on the data, the more benefit you will realize by using LINQ instead of traditional iteration techniques.
Requirements
fusonic/linq is supported on PHP 5.5 and up.
Installation & Usage
The most flexible installation method is using Composer: Simply create a composer.json file in the root of your project:
Install composer and run install command:
Once installed, include vendor/autoload.php in your script to autoload fusonic/linq.
Examples
Calculate the average file size of files in a directory:
Find all files bigger than 1024 bytes and return the fileinfo object:
Search for all users containing "Max 1", Skip 5 items, Take 2 items and select the property ID of each user:
Flatten multiple sequences into one sequence:
Map sequence to array with key/value selectors:
The aggregate method makes it simple to perform a calculation over a sequence of values:
The chunk method makes it simple to split a sequence into chunks of a given size:
List of methods provided by fusonic/linq:
Simple, Consistent and Predictable
One important design goal was the principle of the least surprise. As PHP is a fully dynamic language with nearly no type-safety, it is common to shoot yourself into the foot because of accidentally mixing up incompatible types.
We protect you from these programing errors by asserting that every callback functions you supply to the library must return a correctly typed value. In addition, every supported aggregate function will throw an exception if you are accidentally mixing up incompatible types.
This means that we made this library totally predictable in what it does, and verified that every function has its defined exceptions which are thrown when certain operations fail, or if certain types are not correct.