2017 © Pedro Peláez
 

library array-reader

PHP ArrayReader

image

codeliner/array-reader

PHP ArrayReader

  • Wednesday, July 11, 2018
  • by codeliner
  • Repository
  • 1 Watchers
  • 13 Stars
  • 8,667 Installations
  • PHP
  • 9 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 6 % Grown

The README.md

array-reader

PHP ArrayReader, (*1)

Build Status, (*2)

Installation

Installation of codeliner\array-reader uses composer. For composer documentation, please refer to getcomposer.org. Add following requirement to your composer.json, (*3)

"codeliner/array-reader" : "~2.0"

Usage

You can use the ArrayReader to read single values from a multidimensional array by passing the path to one of the {type}Value() methods. Each {type}Value() method takes a default value as second argument If the path can not be found in the original array, the default is used as return value., (*4)

Example

$arrayReader = new ArrayReader(
    array(
        'hash' => array(
            'with' => array(
                'nested' => 'value'
            )
        )
    )
);

echo $arrayReader->stringValue('hash.with.nested'));

//Output: value

$arrayReader = new ArrayReader(
    array(
        'hash' => array(
            'with' => array(
                'nested' => 'value'
            )
        )
    )
);

echo $arrayReader->stringValue('hash.not.existing.path', 'defaultString'));

//Output: defaultString


//If a key in your array contains a dot you escape it in the path with a backslash

$arrayReader = new ArrayReader(
    array(
        'hash' => array(
            'with.dot.key' => array(
                'nested' => 'value'
            )
        )
    )
);

echo $arrayReader->stringValue('hash.with\.dot\.key.nested'));

//Output: value

//If you need to differentiate between a NULL value and a not existing path, you can explicity check if the path exists:

$arrayReader = new ArrayReader(
    array(
        'hash' => array(
            'with' => array(
                'nested' => null
            )
        )
    )
);

if($arrayReader->pathExists('hash.with.nested')) {
    echo "path exists";
}

//Output: path exists

The Versions

11/07 2018

dev-master

9999999-dev https://github.com/codeliner/array-reader

PHP ArrayReader

  Sources   Download

BSD-3-Clause

The Requires

  • php >=7.1

 

The Development Requires

php util arrayreader

11/07 2018

v2.0

2.0.0.0 https://github.com/codeliner/array-reader

PHP ArrayReader

  Sources   Download

BSD-3-Clause

The Requires

  • php >=7.1

 

The Development Requires

php util arrayreader

11/07 2018

dev-feature/path_exists

dev-feature/path_exists https://github.com/codeliner/array-reader

PHP ArrayReader

  Sources   Download

BSD-3-Clause

The Requires

  • php >=7.1

 

The Development Requires

php util arrayreader

11/07 2018

dev-modernisation

dev-modernisation https://github.com/codeliner/array-reader

PHP ArrayReader

  Sources   Download

BSD-3-Clause

The Requires

  • php >=7.1

 

The Development Requires

php util arrayreader

02/07 2015

v1.2.0

1.2.0.0 https://github.com/codeliner/array-reader

PHP ArrayReader

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

The Development Requires

php util arrayreader

05/07 2014

1.1.0

1.1.0.0 https://github.com/codeliner/array-reader

PHP ArrayReader

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

The Development Requires

php util arrayreader

08/03 2014

1.0

1.0.0.0 https://github.com/codeliner/array-reader

PHP ArrayReader

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

The Development Requires

php util arrayreader