PHP code example of hambrook / config

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

    

hambrook / config example snippets


$Config = new \Hambrook\Config\Config("settings.json");

$value = $Config->get("foo");
// "bar"

$value = $Config->get(["one", "two"]);
// "three"

$value = $Config->get(["nope", "two"]);
// returns `null`, not an error

$value = $Config->get(["nope", "two"], "safe");
// returns "safe", not an error

// Save the JSON encoded data to the file and returns `$this`
$Config->save();

// Get a nested value
$value = Config->one__two
// "three"

// Get a nested value that isn't there
$value = Config->one__bad
// null

// Get a nested value, with a default if the value isn't there
$value = Config->one__bad("default")
// "default"

// Get a nested value, with a default if the value isn't there
$value = Config->one__two = "newthree"
// sets the value to "newthree" then returns `$this`