PHP code example of rancoud / environment

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

    

rancoud / environment example snippets


composer 

// search .env file
$env = new Environment(__DIR__);
$values = $env->getAll();
$value = $env->get('a', 'defaultvalue');

// check if a key exists
$env = new Environment(__DIR__);
$isExists = $env->exists('key1');
$isExists = $env->exists(['key1', 'key2']);

// check if value is set with allowed values
$isAllowed = $env->allowedValues('key1', ['value1', NULL, 'value2']);

$env = new Environment(__DIR__);

// complete with only getenv()
$env->complete(Environment::GETENV);

// complete with $_ENV then $_SERVER
$env->complete(Environment::SERVER | Environment::ENV);

// override with getenv() will erase values
$env->override(Environment::GETENV);

// force using cache (if not exist it will be created)
$env = new Environment(__DIR__);
$env->enableCache();
$values = $env->getAll();

// force using cache (if not exist it will be created)
$env = new Environment(__DIR__);
$env->setEndline('<br />');

// search .env file
$env = new Environment(__DIR__);

// search dev.env file
$env = new Environment(__DIR__, 'dev.env');

// search .env file in folders __DIR__ then '/usr'
$env = new Environment([__DIR__, '/usr']);

// search dev.env file in folders __DIR__ then '/usr'
$env = new Environment([__DIR__, '/usr'], 'dev.env');