PHPackages                             andybursh/plinq - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. andybursh/plinq

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

andybursh/plinq
===============

Functional style operations on arrays

1112PHP

Since Oct 27Pushed 12y agoCompare

[ Source](https://github.com/AndyBursh/plinq)[ Packagist](https://packagist.org/packages/andybursh/plinq)[ RSS](/packages/andybursh-plinq/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

plinq (PHP &gt;= 5.4.0)
=======================

[](#plinq-php--540)

A php library for working with arrays, inspired by .NET's LINQ. Currently supports a small set of actions, but will be expanded. Also supports *lazy evaluation*.

### Available methods

[](#available-methods)

- **on/with** - Starts a chain of actions
- **where** - Filters the input through the provided expression
- **count** - Counts the number of elements in the input (optionally those matching an expression)
- **select** - Transforms each element of the input
- **aggregate** - Applies an accumulator function over each element in the input, returning the final accumulator value
- **head** - Returns the first element in the input (optionally returns the key value pair)
- **tail** - Returns all but the first element in the input
- **max** - Returns the largest element in the input. If the input contains not only numbers, a comparator function must be provided.
- **min** - Returns the smallest element in the input. If the input contains not only numbers, a comparator function must be provided.
- **all** - Finds if all elements in the input match the expression
- **any** - Finds if any element in the input matches the expression. If no expression is provided, returns true if the input is not empty.
- **first** - Returns the first element in the input which matches the expression, otherwise null.

### Example

[](#example)

```
include("plinq.php");
use plinq\plinq;

$numIsEven = function($k, $v)
{
    return ($v % ")==0;
};

$doubleNum = function($k, $v)
{
    return $v * 2;
}

$input = [1, 2, 3, 4, 5, 6];

//plinq can perform chains of actions
$filtered = plinq::with($input)
                 ->where($numIsEven)
                 ->select($doubleNum);

//Or a single action
$numOfElements = plinq::count($input);

```

The result of a plinq chain is a **plinqWrapper** object. This can be manipulated like an array but, crucially, will not be recognised as one by functions hinting an array. To get around this, either cast the result to an array or call toArray.

```
$castArray = (array)$filtered;
$methodArray = $filtered->toArray();

```

Until a result is converted to an array, you can still call plinq methods on it.

```
$newFilter = plinq::with($input)
                  ->where($numIsEven);

print "The first even number is ".$newFilter[0];
print "The double of the last number is " + $newFilter->select($doubleNum)[2];

```

### Lazy evaluation

[](#lazy-evaluation)

Using lazy evaluation with Plinq is done almost precisely like normal. The only difference is there's no access to the resulting value until exec has been called, returning an array (not an ArrayObject like standard plinq).

```
include("lazyPlinq.php");
use plinq\lazyPlinq;

$numIsEven = function($k, $v)
{
    return ($v % ")==0;
};

$doubleNum = function($k, $v)
{
    return $v * 2;
}

$input = [1, 2, 3, 4, 5, 6];

$filtered = lazyPlinq::with($input)
                     ->where($numIsEven)
                     ->select($doubleNum)
                     ->exec();

```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/09b3c06436b643d90562c6d2ba56cb3da4a0c265a65f563eba815d5f8a84bc2e?d=identicon)[AndyBursh](/maintainers/AndyBursh)

---

Top Contributors

[![AP-Hunt](https://avatars.githubusercontent.com/u/1747386?v=4)](https://github.com/AP-Hunt "AP-Hunt (18 commits)")

### Embed Badge

![Health badge](/badges/andybursh-plinq/health.svg)

```
[![Health](https://phpackages.com/badges/andybursh-plinq/health.svg)](https://phpackages.com/packages/andybursh-plinq)
```

###  Alternatives

[digitoimistodude/air-helper

Plugin provides helpful functions and modifications for WordPress projects.

565.8k2](/packages/digitoimistodude-air-helper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
