PHPackages                             rpnzl/arrch - 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. rpnzl/arrch

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

rpnzl/arrch
===========

Array queries for PHP 5.3

v1.1.1(12y ago)37134.6k↑435%112MITPHPPHP &gt;=5.3.0

Since Jun 11Pushed 11y ago5 watchersCompare

[ Source](https://github.com/rpnzl/arrch)[ Packagist](https://packagist.org/packages/rpnzl/arrch)[ Docs](https://github.com/rpnzl/arrch)[ RSS](/packages/rpnzl-arrch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (2)

arrch v1.1
----------

[](#arrch-v11)

A PHP library for array queries, sorting, and more.

### Usage

[](#usage)

The main Arrch method, `find()`, is most commonly used and is a combination of Arrch's `where()`, `sort()`, and limit/offset options. `where()` and `sort()` can be used on their own, if needed.

#### Data

[](#data)

We need some data to start with, preferably a large array of objects or multidimensional arrays. Here's a cross section of an example array...

```
// this is a LARGE array of multidimensional arrays
$data = array(
    ...,
    4037 => array(
        'name'  => array(
            'first' => 'Brian',
            'last'  => 'Searchable'
        ),
        'null'  => null,
        'age'   => 27,
        'email' => 'bsearchable@example.com',
        'likes' => array(
            'color' => 'blue',
            'food'  => 'cheese',
            'sauce' => 'duck'
        ),
    ),
    ...,
);

```

#### Find() Method

[](#find-method)

This is the method you'll probably use most often, default configuration is below.

```
Arrch\Arrch::find(
    $data, // array of multidimensional arrays
    $options = array(
        'where'         => array(),
        'limit'         => 0,
        'offset'        => 0,
        'sort_key'      => null, // dot notated array key or object property
        'sort_order'    => 'ASC' // 'ASC' or 'DESC'
    ),
    $key = 'all' // 'all', 'first', 'last', an index of the $data array
);

```

#### Quick Example

[](#quick-example)

Be sure to include the arrch.php file in your script or app.

```
include 'lib/arrch.php';

```

We'll use Arrch to try and find Brian using a few conditions that return `true` for Brian's data. You can traverse the multidimensional arrays in your query by using dot (.) notation, and use a standard collection of operators (which are listed below) to determine a match.

```
// this query would find our Brian, plus any other Brians over age 25
// Remember that the Arrch class is part of the Arrch namespace
$results = Arrch\Arrch::find($data, array(

    'sort_key'  => 'name.last',
    'where'     => array(
        // tests for an exact match (===)
        array('name.first', 'Brian'),

        // use an operator
        array('age', '>', 25),
    ),

), 'first');

```

#### Where Conditions

[](#where-conditions)

Arrch conditions are pretty flexible, and can be thought of like MySQL's `AND`, `OR`, `LIKE`, and `IN` operators. First, a list of valid operators.

```
// valid conditional operators
array('==', '===', '!=', '!==', '>', '=', '', 25),

    // IN statement
    array('likes.food', array('toast', 'foie gras', 'cheese')),

    // OR/IN combined
    array(array('email', 'age'), array(27, 'goober@goob.co')),

    // Yes, you can compare to NULL
    array('null', null)

)

```

You may be wondering about the tilde (~) operator. That one is comparable to MySQL's `LIKE` statement. You can use it to check for similarity in strings, numbers, and even determine if an associative array key exists.

```
'where' => array(

    // First names that contain 'br'
    array('name.first', '~', 'br'),

    // Find folks that have a favorite food defined
    array('likes', '~', 'food')

)

```

### Limitations

[](#limitations)

Use this library in large-scale production environments at your own risk. Processing large arrays in runtime memory is a slow process, and you could experience major hangups when dealing with huge amounts of data. In those instances, why not stick with a legitimate database interface and solution like the PHP core extensions for MySQL, PostgreSQL, MongoDB, etc. and associated, more mature abstracted database libraries.

Arrch may find it's a niche in smaller-scale, flat-file storage environments. Of course, this library could work with any database solution, but you'd have to load the entirety of the collection into memory at once in order to query against it. That might not be a good time.

At the very least, it's fun to play around with a simple PHP solution that doesn't require MySQL. Just be honest with yourself about your project's requirements *before* you begin, and don't code yourself into a hole!

### License

[](#license)

[MIT](http://opensource.org/licenses/MIT)

### Author

[](#author)

Available at [rpnzl.com](http://rpnzl.com), [GitHub](http://www.github.com/rpnzl), and [Twitter](http://www.twitter.com/rpnzldesign).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.1% 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

2

Last Release

4724d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1219195?v=4)[Michael Giuliana](/maintainers/rpnzl)[@rpnzl](https://github.com/rpnzl)

---

Top Contributors

[![rpnzl](https://avatars.githubusercontent.com/u/1219195?v=4)](https://github.com/rpnzl "rpnzl (33 commits)")[![dkorsak](https://avatars.githubusercontent.com/u/2765598?v=4)](https://github.com/dkorsak "dkorsak (1 commits)")

---

Tags

searcharrayquery

### Embed Badge

![Health badge](/badges/rpnzl-arrch/health.svg)

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

###  Alternatives

[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k411.1M1.2k](/packages/doctrine-collections)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)

PHPackages © 2026

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