PHP code example of miladm / config

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

    

miladm / config example snippets


use miladm\Config;

$config = new Config([
    'db_host' => 'localhost',
    'db_port' => 3306,
    'db_user' => 'myuser',
    'db_pass' => 'mypass',
    'db_name' => 'mydb',
]);

$host = $config->get('db_host');
$port = $config->get('db_port');
$user = $config->get('db_user');
$pass = $config->get('db_pass');
$name = $config->get('db_name');

putenv('DB_HOST=localhost');
putenv('DB_PORT=3306');
putenv('DB_USER=myuser');
putenv('DB_PASS=mypass');
putenv('DB_NAME=mydb');

$host = $config->get('db_host'); // returns 'localhost'
$port = $config->get('db_port'); // returns 3306
$user = $config->get('db_user'); // returns 'myuser'
$pass = $config->get('db_pass'); // returns 'mypass'
$name = $config->get('db_name'); // returns 'mydb'

$host = $config->db_host;
$port = $config->db_port;
$user = $config->db_user;
$pass = $config->db_pass;
$name = $config->db_name;

$config->get('db_host'); // fetches from configuration data or environment variables and caches the value
$config->cache['db_host'] = null; // clears the cache for the 'db_host' key
$config->get('db_host'); // fetches from configuration data or