1. Go to this page and download the library: Download jbzoo/data 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/ */
use function JBZoo\Data\data;
use function JBZoo\Data\ini;
use function JBZoo\Data\json;
use function JBZoo\Data\phpArray;
use function JBZoo\Data\yml;
$config = data([/* Assoc Array */]); // Any PHP-array or simple object, serialized data
$config = ini('./configs/some.ini'); // Load configs from ini file (or string, or simple array)
$config = yml('./configs/some.yml'); // Yml (or string, or simple array). Parsed with Symfony/Yaml Component.
$config = json('./configs/some.json'); // JSON File (or string, or simple array)
$config = phpArray('./configs/some.php'); // PHP-file that must return array
// Read
$config->get('key', 42); // Returns value if it exists oR returns default value
$config['key']; // As regular array
$config->key; // As regular object
// Read nested values without PHP errors
$config->find('deep.config.key', 42); // Gets `$config['very']['deep']['config']['key']` OR returns default value
// Write
$config->set('key', 42);
$config['key'] = 42;
$config->key = 42;
// Isset
$config->has('key');
isset($config['key']);
isset($config->key);
// Unset
$config->remove('key');
unset($config['key']);
unset($config->key);
$config->get('key', 42, 'int'); // Smart converting to integer
$config->find('key', 42, 'float'); // To float
$config->find('no', 'yes', 'bool'); // Smart converting popular word to boolean value
$config->get('key', 42, 'strip, trim'); // Chain of filters
// Your custom handler
$config->get('key', 42, function($value) {
return (float)str_replace(',', '.', $value);
});
$config->search($needle); // Find a value also in nested arrays/objects
$config->flattenRecursive(); // Return flattened array copy. Keys are <b>NOT</b> preserved.