PHPackages                             linq/php-linq - 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. linq/php-linq

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

linq/php-linq
=============

the fast and modern library for easy data manipulation

1.0.0(9y ago)76.2k6[4 issues](https://github.com/gallas12/php-linq/issues)[1 PRs](https://github.com/gallas12/php-linq/pulls)Apache-2.0PHP

Since Oct 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/gallas12/php-linq)[ Packagist](https://packagist.org/packages/linq/php-linq)[ RSS](/packages/linq-php-linq/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (8)Used By (0)

php-linq
========

[](#php-linq)

Linq technology in php language.

### Install

[](#install)

```
composer require linq/php-linq ~1.0
```

### class Linq

[](#class-linq)

Base class that performs queries over the collections of objects and over the array.

**List of methods**

- from() - set primary source
- first() - return first item from collection
- last() - return last item from collection
- select($key = null, $key2 = null) - return result. You can use callable as first param
- count() - return length of collection
- take($offset, $length = null) - return first x items || return interval
- skip($offset) - skip x items a and return other data
- where($condition) - returns only elements that match a given condition
- reverse() - reverse collection
- orderBy($column, $desc = false) - sort. desc = descending. defalt asc = ascending
- distinct() - return unique items
- takeWhile($requirement) - combination = where(condition) + select()
- union($array) - union in sql
- groupBy($key) - Group data
- innerJoin($array) - return only elements that combine both fields
- leftJoin($array) - the first collection will list all entries, even those which do not connect with other collections
- on($condition) - Condition for join two collections
- in($filter) - Accepts an array of values which elements must acquire
- notIn($filter) - negation of "in" method
- onlyKeys($keys) - filtering data by key
- row\_to\_column($main\_node) - split by a specific key. This key becomes a major hub

**testing data**

```
protected $students = array(
    array("name" => "Milan", "surname" => "Gallas", "age" => 20, "Job" => "php Programátor"),
    array("name" => "Amdrea", "surname" => "Novotná", "age" => 17, "Job" => "java Programátor"),
    array("name" => "Honza", "surname" => "Pulkert", "age" => 27, "Job" => "c# Programátor"),
    array("name" => "Nikola", "surname" => "Světnická", "age" => 23, "Job" => "php Programátor"),
    array("name" => "Nikola", "surname" => "Světnická", "age" => 23, "Job" => "php Programátor"),
    array("name" => "Petr", "surname" => "Grůdl", "age" => 31, "Job" => "java Programátor"),
);

protected $sports = array(
    array("userName" => "Milan", "sport" => "šachy", "active" => true),
    array("userName" => "Milan", "sport" => "karate", "active" => false),
    array("userName" => "Honza", "sport" => "box", "active" => true),
    array("userName" => "Honza", "sport" => "fotbal", "active" => false),
    array("userName" => "Milan", "sport" => "hokej", "active" => true),
    array("userName" => "Petr", "sport" => "tenis", "active" => true)
);
```

**example of use**

```
require 'vendor/autoload.php';

//init base linq class
$linq = \Linq\LinqFactory::createLinq();

//filtering data - select only users who are older than 23
$linq
	->from($userData)
	->where(function($item){
		if($item["age"] > 23) return $item;
	})

//clasic select
var_dump($linq->select());
//select data with function
var_dump(
		$linq->select(function($person){
			$person["age"]*=2;
			return $person;
		})
	);
//or
var_dump(
		$linq->select(function($user){
			//return $user["name"]  //you can try = return string
			return array("userName" => $user["name"]); //return array
		})
	);

//short select = less typing :D
var_dump( $linq->select("age") );  echo '';
var_dump( $linq->select("name", "age") ); echo '';
//$linq->select("name", "age") =>
var_dump(
	$linq->select(function($user){
		return array($user["name"] => $user["age"]);
	})
);

//full use with join method and groupBy
$linq
	->from($userData)
	//->innerJoin($sportData)
	->leftJoin($sportData)
	->on(function($user, $sport){
		return ($user["name"] == $sport["userName"]);
	})
	->groupBy("Job")
	->select()
```

### class JsonLinq

[](#class-jsonlinq)

The class takes data source in JSON format. Returns array.

**testing data**

```
$userJsonData = json_encode($userData);
$sportJsonData = json_encode($sportData);
```

**example of use**

```
$linq = \Linq\LinqFactory::createJsonLinq();

	echo ''; var_dump(
		$linq
			->from($userJsonData)
			->takeWhile(function($user){
				return ($user["Job"] === "php Programátor" && $user["age"] > 20);
			})
	);
```

### class XmlLinq

[](#class-xmllinq)

The class takes data source in JSON format. Returns array.

> The "from" method accept string or SimpleXmlElement. If out choose xml in string, so you will work with array. If you choose xml in SimlpeXmlElement object, so you will work with collection of std objects.

**testing data**

```
$sportXml =
'

         Milan
         šachy
         true

         Milan
         karate
         false

         Milan
         hokej
         true

         Honza
         box
         true

         Honza
         fotbal
         false

         Petr
         tenis
         true

';

//users
$userXml = '

         Milan
         Gallas
         20
         php Programátor

         Amdrea
         Novotná
         17
         Java Programátor

         Honza
         Pulkert
         27
         c# Programátor

         Nikola
         Světnická
         23
         php Programátor

         Nikola
         Světnická
         23
         php Programátor

         Petr
         Grůdl
         31
         Java Programátor

	';
```

**example of use**

```
    //first example. Source is string
	echo '';
	var_dump(
		\Linq\LinqFactory::createXmlLinq()
			->from($userXml)
			->leftJoin($sportXml)
			->on(function($user, $sport){
				return ($user["name"] == $sport["userName"]);
			})
			->select()
	);

	//second example group by and reverse - source is string
	echo "";
	var_dump(
		\Linq\LinqFactory::createXmlLinq()->from($userXml)->groupBy("Job", "name")->reverse()->select();
	);
	echo "";

	//third examlple - source is simpleXmlElement. use condition on collection of objects and sort by orderBy function descending
	$xmlElemetn = new SimpleXMLElement($userXml);
	echo '';
	var_dump(
		\Linq\LinqFactory::createXmlLinq()
			->from($xmlElemetn)
			->where(function($user){
				return (strlen($user->name) > 5);
			})
			->orderBy("age", true)
			->select()
	);
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance9

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

3494d ago

Major Versions

0.1.2 → 1.0.02016-10-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/f9d26dd6b62e71ac958aba911363771de3545a287df1be67c5f62e398e4c7cd6?d=identicon)[Milan Gallas](/maintainers/Milan%20Gallas)

---

Top Contributors

[![gallas12](https://avatars.githubusercontent.com/u/16787305?v=4)](https://github.com/gallas12 "gallas12 (2 commits)")

### Embed Badge

![Health badge](/badges/linq-php-linq/health.svg)

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

PHPackages © 2026

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