mkomorowski/php-dot-get

Array dot notation access

dev-master 2015-12-09 12:37 UTC

This package is not auto-updated.

Last update: 2024-11-09 18:48:52 UTC


README

Array dot notation access

##Installation

The package can be installed via Composer by adding to the composer.json require block.

{
    "require": {
        "mkomorowski/php-dot-get": "dev-master"
    }
}

Then update application packages by running the command:

php composer.phar install

##Usage

$dot = new mKomorowski\Notation\Dot;

Get value from array

$array = array(
    'name' => 'Name',
    'firstname' => 'FirstName',
    'address' => array(
        'street' => '',
        'city' => 'Leeds'
    )
);

$dot->get($array, 'address.city'); // 'Leeds'

Tell if the value isset in array

$dot->exists($array, 'address.city'); // true

Set default value returned if given key is not found in array

$dot->get($array, 'address.country') // null

$dot->setDefault('undefined');

$dot->get($array, 'address.country') // 'undefined'

Compare requested value with given one

$dot->assert($array, 'name', 'Name') // true