PHP code example of jsc-php / configs

1. Go to this page and download the library: Download jsc-php/configs 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/ */

    

jsc-php / configs example snippets


use JscPhp\Configs\Config;

// Load a config file (format is determined by file extension)
$config = new Config('test.php');

// Get values using magic methods
$db = $config->database;
$db_host = $config->database['host'];

// Get values using get function
$db = $config->get('database');
$db_host = $config->get('database')['host'];
$db_host = $config->get('database','host');
$db_host = $config->get('database.host');


// Set values
$config->debug = true;
$config->set('debug', true);
$config->set('debug.level', 'info');
$config->set(['debug','level'], 'info');

// Changes are automatically saved when $config goes out of scope

$config = new Config('config.yaml', ['autosave' => false]);

$config->theme = 'dark';

// Manual save 

use JscPhp\Configs\Config;
use JscPhp\Configs\Types\Type;

$config = new Config('settings.ini');

// Save as JSON
$config->saveAs('settings.json');

$config->delete('key1'); //Deletes array key1
$config->delete('key1.key2'); //Deletes array key2 within key1
$config->delete('key1','key2'); //Deletes array key2 within key1
bash
composer