PHPackages                             boxblinkracer/xpatharray - 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. boxblinkracer/xpatharray

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

boxblinkracer/xpatharray
========================

XPath Access for Arrays

1.0.1(7y ago)239.5k↑18.2%MITPHPPHP &gt;=7.0

Since Jul 3Pushed 7y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (0)

XPathArray - Easy XPath Access for your Arrays
==============================================

[](#xpatharray---easy-xpath-access-for-your-arrays)

[![Downloads](https://camo.githubusercontent.com/64287e5aadaa6ab3a168630633bd69c786c47c2d76c4b6448bd9d8ae79b8e118/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626f78626c696e6b72616365722f787061746861727261792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boxblinkracer/xpatharray)[![Latest stable version](https://camo.githubusercontent.com/daf875b67b258dec480d31a17848bd6d177e792ca73cc2325bcf9b8305d4ba12/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626f78626c696e6b72616365722f787061746861727261792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boxblinkracer/xpatharray)[![PHP from Packagist](https://camo.githubusercontent.com/f0d562f12c940fe2664eb725562f352178130c1c2f0acef1942b3ae8c5bab29f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f626f78626c696e6b72616365722f787061746861727261792e7376673f7374796c653d666c61742d737175617265)](./composer.json)[![GitHub stars](https://camo.githubusercontent.com/5a5cef00b8ddf9d48daac8a50ed623a32bc283be8e3ba2e18aa91dbc9e5afef7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f626f78626c696e6b72616365722f787061746861727261792e7376673f7374796c653d666c61742d737175617265266c6162656c3d5374617273267374796c653d666c61742d737175617265)](https://github.com/boxblinkracer/xpatharray/stargazers)[![MIT licensed](https://camo.githubusercontent.com/ccd11250c91f216c87a8056569c1d2da1655a40b6161e25c3ef10c478b9f5235/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f626f78626c696e6b72616365722f787061746861727261792e7376673f7374796c653d666c61742d737175617265)](https://github.com/boxblinkracer/xpatharray/blob/master/LICENSE)

Why XPathArrays instead of Arrays?
----------------------------------

[](#why-xpatharrays-instead-of-arrays)

...small and simple, but still powerful... If you use basic Arrays in PHP you are familiar with the `array_key_exists` function. And yes, this does really blow up your code if you have multiple levels within your array.

If you check for existing keys, the only thing you get is a `PHP Notice Error`, and that obviously doesn't result in an Exception.

With XPathArray you get the following:

- Easy **XPath Selection** in multiple levels, e.g. *"/customer/address/street"*
- Real **XPathKeyNotFound Exceptions** instead of PHP Notices
- **Default Values** for missing keys or values
- ...and a more lightweight code... :)

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

[](#installation)

This package uses Composer, please checkout the [composer website](https://getcomposer.org) for more information.

The following command will install `xpatharray` into your project. It will also add a new entry in your `composer.json` and update the `composer.lock` as well.

```
$ composer require boxblinkracer/xpatharray
```

> This package follows the PSR-4 convention names for its classes, which means you can easily integrate `xpatharray` classes loading in your own autoloader.

What now?
---------

[](#what-now)

Here are a few examples what to do with XPathArray objects.

### With Exceptions

[](#with-exceptions)

In the first example, we access the content of our customer array using XPath syntax. If a key is not found, we will get a `XPathNotFoundException`.

This is perfect, if you want to simply **use and validate your structure at once**.

```
