PHPackages                             nahid/qarray - 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. nahid/qarray

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

nahid/qarray
============

QArray is a PHP abstraction for querying array

v2.1.0(1y ago)108415.2k↓61%23[5 issues](https://github.com/nahid/qarray/issues)[1 PRs](https://github.com/nahid/qarray/pulls)2MITPHPPHP &gt;=7.4CI failing

Since Dec 19Pushed 1y ago8 watchersCompare

[ Source](https://github.com/nahid/qarray)[ Packagist](https://packagist.org/packages/nahid/qarray)[ Docs](https://github.com/nahid/qarray)[ RSS](/packages/nahid-qarray/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (3)Versions (15)Used By (2)

 [![PHP QArray](https://raw.githubusercontent.com/nahid/qarray/master/media/example.png)](https://raw.githubusercontent.com/nahid/qarray/master/media/example.png)

\# QArray - Query Engine For Array **QArray** is query engine for PHP array data. It helps to developers querying any kind of array data with ORM like feel.

Installation
------------

[](#installation)

```
composer require nahid/qarray

```

Implementation
--------------

[](#implementation)

Since QArray is an abstract layer of code, so you have to implement your own system with a lots of pre build functionality.

Lets start our first implementation for JSON data.

```
class JsonQueryEngine extends \Nahid\QArray\QueryEngine
{
    public function readPath($path)
    {
        $data = file_get_contents($path);

        return json_decode($data, true);
    }

    public function parseData($data)
    {
        return json_decode($data, true);
    }
}
```

Here you see we implement a new engine for JSON data. `QueryEngine` is an abstract class, so we have to implement its two abstract function `readPath` and `parseData`

Usage
-----

[](#usage)

Our implementation were complete, now we can use this implementation.

```
class Product
{
    protected $query;

    public function __construct(\Nahid\QArray\QueryEngine $query)
    {
        $this->query = $query;
    }

    public function getMacbook()
    {
        try {
            return $this->query
                ->from('.')
                ->where('cat', 2)
                ->get();
        } catch (\Exception $e) {
           return false;
        }

    }
}
```

Here we develop a class for Products and this class use `JsonQueryEngine` for fetch data from JSON file.

Lets see, how to use it.

here is our JSON file `data.json`

```
[
  {"id":1, "name":"iPhone", "cat":1, "price": 80000},
  {"id":2, "name":"macbook pro 2017", "cat": 2, "price": 210000},
  {"id":3, "name":"Redmi 3S Prime", "cat": 1, "price": 12000},
  {"id":4, "name":"Redmi 4X", "cat":1, "price": 15000},
  {"id":5, "name":"macbook air", "cat": 2, "price": 110000}
]
```

And now we read it to querying data.

```
$data = new JsonQueryEngine('data.json');
$query = new SomethingBuilder($data);

dump($query->getMacbook()->toArray());
```

**Output**

```
array:2 [
  1 => array:4 [
    "id" => 2
    "name" => "macbook pro 2017"
    "cat" => 2
    "price" => 210000
  ]
  4 => array:4 [
    "id" => 5
    "name" => "macbook air"
    "cat" => 2
    "price" => 110000
  ]
]

```

Pretty neat, huh?

Let's explore the full API to see what else magic this library can do for you. Shall we?

API
---

[](#api)

**List of API:**

- [fetch](#fetch)
- [find](#findpath)
- [at](#atpath)
- [from](#frompath)
- [select](#select)
- [except](#except)
- [then](#then)
- [collect](#collect)
- [json](#json)
- [import](#import)
- [where](#wherekey-op-val)
- [orWhere](#orwherekey-op-val)
- [whereIn](#whereinkey-val)
- [whereNotIn](#wherenotinkey-val)
- [whereNull](#wherenullkey)
- [whereNotNull](#wherenotnullkey)
- [whereStartsWith](#wherestartswithkey-val)
- [whereEndsWith](#whereendswithkey-val)
- [whereContains](#wherecontainskey-val)
- [whereMatch](#wherematch-val)
- [whereInstance](#whereinstance-val)
- [whereDataType](#wheredatatype-val)
- [sum](#sumproperty)
- [count](#count)
- [size](#size)
- [max](#maxproperty)
- [min](#minproperty)
- [avg](#avgproperty)
- [first](#first)
- [last](#last)
- [nth](#nthindex)
- [column](#column)
- [implode](#implode)
- [exists](#exists)
- [groupBy](#groupbyproperty)
- [sort](#sortorder)
- [sortBy](#sortbyproperty-order)
- [reset](#resetdata)
- [copy](#copy)
- [toJson](#tojson)
- [keys](#keys)
- [values](#values)
- [filter](#filter)
- [transform](#transform)
- [each](#each)
- [pipe](#pipe)
- [chunk](#chunk)
- [macro](#macro)

### Available operation for where clause

[](#available-operation-for-where-clause)

- `key` -- the property name of the data. Or you can pass a Function here to group multiple query inside it. See details in [example](examples/where.js)
- `val` -- value to be matched with. It can be a *int*, *string*, *bool* or even *Function* - depending on the `op`.
- `op` -- operand to be used for matching. The following operands are available to use:

    - `=` : For weak equality matching
    - `eq` : Same as `=`
    - `!=` : For weak not equality matching
    - `neq` : Same as `!=`
    - `==` : For strict equality matching
    - `seq` : Same as `==`
    - `!==` : For strict not equality matching
    - `sneq` : Same as `!==`
    - `>` : Check if value of given **key** in data is Greater than **val**
    - `gt` : Same as `>`
    - `=`
    - `from('users')
->where('id', '=', 1)
->where('location', '=', 'barisal')
->get();
```

See a detail example [here](examples/where.php).

### `orWhere(key, op, val)`

[](#orwherekey-op-val)

Parameters of `orWhere()` are the same as `where()`. The only difference between `where()` and `orWhere()` is: condition given by the `orWhere()` method will OR-ed the result with other conditions.

For example, if you want to find the users with *id* of `1` or `2`, you can do it like this:

```
$q = new Jsonq('data.json');
$res = $q->from('users')
->where('id', '=', 1)
->orWhere('id', '=', 2)
->get();
```

See detail example [here](examples/or-where.php).

### `whereIn(key, val)`

[](#whereinkey-val)

- `key` -- the property name of the data
- `val` -- it should be an **Array**

This method will behave like `where(key, 'in', val)` method call.

### `whereNotIn(key, val)`

[](#wherenotinkey-val)

- `key` -- the property name of the data
- `val` -- it should be an **Array**

This method will behave like `where(key, 'notin', val)` method call.

### `whereNull(key)`

[](#wherenullkey)

- `key` -- the property name of the data

This method will behave like `where(key, 'null')` or `where(key, '=', null)` method call.

### `whereNotNull(key)`

[](#wherenotnullkey)

- `key` -- the property name of the data

This method will behave like `where(key, 'notnull')` or `where(key, '!=', null)` method call.

### `whereStartsWith(key, val)`

[](#wherestartswithkey-val)

- `key` -- the property name of the data
- `val` -- it should be a String

This method will behave like `where(key, 'startswith', val)` method call.

### `whereEndsWith(key, val)`

[](#whereendswithkey-val)

- `key` -- the property name of the data
- `val` -- it should be a String

This method will behave like `where(key, 'endswith', val)` method call.

### `whereContains(key, val)`

[](#wherecontainskey-val)

- `key` -- the property name of the data
- `val` -- it should be a String

This method will behave like `where(key, 'contains', val)` method call.

### `whereDataType(key, val)`

[](#wheredatatypekey-val)

- `key` -- the property name of the data
- `val` -- it should be a String

This method will behave like `whereDataType(key, 'type', val)` method call.

### `sum(column)`

[](#sumcolumn)

- `column` -- the property name of the data

Bugs and Issues
---------------

[](#bugs-and-issues)

If you encounter any bugs or issues, feel free to [open an issue at github](https://github.com/nahid/qarray/issues).

Also, you can shoot me an email to  for hugs or bugs.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity51

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 90.8% 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 ~199 days

Recently: every ~402 days

Total

12

Last Release

555d ago

Major Versions

v0.0.1 → v1.0.02018-12-25

v1.2.0 → v2.0-alpha12020-07-14

v2.1.0 → v3.0.0.x-dev2024-12-25

PHP version history (6 changes)v0.0.1PHP &gt;=5.5.0

v1.2.0PHP &gt;=5.6.0

v2.0-alpha1PHP &gt;=7.0

v2.0.0PHP &gt;=5.6

2.x-devPHP &gt;=7.4

v3.0.0.x-devPHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3167309?v=4)[Nahid Bin Azhar](/maintainers/nahid)[@nahid](https://github.com/nahid)

---

Top Contributors

[![nahid](https://avatars.githubusercontent.com/u/3167309?v=4)](https://github.com/nahid "nahid (59 commits)")[![hashemirafsan](https://avatars.githubusercontent.com/u/16275582?v=4)](https://github.com/hashemirafsan "hashemirafsan (4 commits)")[![me-shaon](https://avatars.githubusercontent.com/u/831997?v=4)](https://github.com/me-shaon "me-shaon (1 commits)")[![Shipu](https://avatars.githubusercontent.com/u/4118421?v=4)](https://github.com/Shipu "Shipu (1 commits)")

---

Tags

arrayarray-queryenginephpqarrayqueryphparrayquery

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nahid-qarray/health.svg)

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

###  Alternatives

[dotty/dotty

Easy access to array data using dot notation

1293.8k1](/packages/dotty-dotty)

PHPackages © 2026

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