Build Quality Coverage Release License


PHP Integrated query

View project onGitHub

What is Pinq?

Based off the .NET's Linq (Language integrated query), Pinq unifies querying across arrays/iterators and external data sources, in a single readable and concise fluent API.

A quick example

The following shows an example query using the Pinq library:

$youngPeopleDetails = $people
        ->where(function ($row) { return $row['age'] <= 50; })
        ->orderByAscending(function ($row) { return $row['firstName']; })
        ->thenByAscending(function ($row) { return $row['lastName']; })
        ->indexBy(function ($row) { return $row['phoneNumber']; })
        ->select(function ($row) { 
            return [
                'fullName' => $row['firstName'] . ' ' . $row['lastName'],
                'address' => $row['address'],
                'dateOfBirth' => $row['dateOfBirth'],

The beauty of Pinq is as follows, the above query may be executing against a set of arrays or possibly against database table. Pinq blurs the lines between in-memory and external data-source, using the most powerful and natural language available to PHP developers: ... PHP.

Why Pinq?

Considering the vast number of Linq implementations currently available for php, why another? Besides the fact most of the others are incomplete/broken without a maintainer nor contributors, they are not real Linq implementations. Sure, offering some nice array handling syntax is cool, but not only what Linq is about. Pinq aims to provide:

  • Well structured and tested code base
  • Full composer and PSR-4 support
  • Complete and thorough documentation
  • Linq-style fluent query API with lazy evaluation and immutable query objects
  • Truly seamless external query support
  • Full support for PHP closures and callable syntax (No magic strings)
  • And even building on the original Linq with offering an additional mutable query API


Add the package to your composer.json:

    "require": {
        "timetoogo/pinq": "~2.1"