A PHP function to safely extract information from a multi-dimensional object or array.

Installs: 6 160

Dependents: 2

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 1

Open Issues: 0

pkg:composer/travis/ex

v1.0.1 2022-01-04 16:23 UTC

This package is not auto-updated.

Last update: 2025-10-07 13:16:10 UTC


README

A PHP function to safely extract information from a multi-dimensional object or array.

Install

Normall install via Composer.

Usage

$array = array(
    'foo' => array(
        'bar' => array(
            'foo' => array(
                'bar' => 'asdf'
            )
        )
    )
);

$value = ex($array, 'foo.bar.foo.bar'); // returns "asdf"
$value = ex($array, 'foo.bar.foo.invalid_key'); // returns null
$value = ex($array, 'foo.bar.foo.invalid_key', 'default'); // returns "default"

Updates

I added another helper function to safely count arrays:

$array = null;
$count = excount($array); // returns 0 instead of error

I wanted this to fix a change in PHP 7.4 which breaks sizeof().