Download the PHP package rpnzl/arrch without Composer

On this page you can find all versions of the php package rpnzl/arrch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package arrch

arrch v1.1

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

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

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' => '[email protected]',
        'likes' => array(
            'color' => 'blue',
            'food'  => 'cheese',
            'sauce' => 'duck'
        ),
    ),
    ...,
);

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

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

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('==', '===', '!=', '!==', '>', '<', '>=', '<=', '~');

Second, examples of valid conditions.

'where' => array(

    // OR statement
    array(array('name.first', 'likes.color'), 'blue'),

    // AND statement, including another condition
    array('age', '>', 25),

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

    // OR/IN combined
    array(array('email', 'age'), array(27, '[email protected]')),

    // 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

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

MIT

Author

Available at rpnzl.com, GitHub, and Twitter.


All versions of arrch with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rpnzl/arrch contains the following files

Loading the files please wait ....