A strictly typed array reader for PHP.
- PHP 7.0+
composer require selective/array-reader
You can use the ArrayReader
to read single values from a multidimensional
array by passing the path to one of the get{type}()
and find{type}()
methods.
Each get*() / find*()
method takes a default value as second argument.
If the path cannot be found in the original array, the default is used as return value.
A get*()
method returns only the declared return type.
If the default value is not given and the element cannot be found, an exception is thrown.
A find*()
method returns only the declared return type or null
.
No exception is thrown if the element cannot be found.
<?php
use Selective\ArrayReader\ArrayReader;
$arrayReader = new ArrayReader([
'key1' => [
'key2' => [
'key3' => 'value1',
]
]
]);
// Output: value1
echo $arrayReader->getString('key1.key2.key3');
The MIT License (MIT). Please see License File for more information.