PHP code example of codeliner / array-reader
1. Go to this page and download the library: Download codeliner/array-reader library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codeliner / array-reader example snippets
$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
sh
"codeliner/array-reader" : "~2.0"