PHP code example of into-the-void / env

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

    

into-the-void / env example snippets


use IntoTheVoid\Env\Env;

getenv('APP_DEBUG');   // string(4) "true"
Env::get('APP_DEBUG'); // bool(true)

getenv('DB_PORT');     // string(4) "5432"
Env::get('DB_PORT');   // int(5432)

Env::getString('DB_HOST'); // string(9) "localhost"
Env::getBool('APP_DEBUG'); // bool(true)
Env::getInt('DB_PORT');    // int(5432)
Env::getFloat('APP_MUL');  // double(1.25)
Env::getList('PATH', ':'); // array(2) { "/usr/local/bin", "/usr/bin" }

Env::has('DB_PORT');       // bool(true)
Env::set('DB_PORT', 3306);
Env::remove('DB_PORT');

use function IntoTheVoid\Env\env;

env('APP_DEBUG'); // bool(true)

Env::getBool('NO_SUCH_VAR');         // NULL
Env::getRequiredBool('NO_SUCH_VAR'); // Fatal error: MissingEnvironmentVariable

Env::getBool('NOT_A_BOOL');                // Fatal error: UnparsableValue
Env::getBool('NOT_A_BOOL', strict: false); // NULL