1. Go to this page and download the library: Download ddrv/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/ */
ddrv / env example snippets
use Ddrv\Env\Env;
use Ddrv\Env\VariableProvider\EnvVariableProvider;
use Ddrv\Env\VariableProvider\FileVariableProvider;
/*
* $_ENV = [
* 'APP_VAR_1' => 'value1',
* 'APP_VAR_2' => 'value2',
* ];
*/
$env = new Env(
new EnvVariableProvider(),
new FileVariableProvider('/path/to/project/.env'),
);
$env->get('APP_VAR_1'); // returns 'value1'
$env->get('APP_VAR_2'); // returns 'value2'
$env->get('APP_VAR_3'); // returns 'value3'
$env->get('APP_VAR_4'); // returns null
$env->get('APP_VAR_5', 'defaultValue'); // returns 'defaultValue'
use Ddrv\Env\Env;
use Ddrv\Env\VariableProvider\EnvVariableProvider;
use Ddrv\Env\VariableProvider\FileVariableProvider;
use Ddrv\Env\VariableProvider\PrefixedVariableProvider;
/*
* $_ENV = [
* 'APP_VAR_1' => 'value1',
* 'APP_VAR_2' => 'value2',
* ];
*/
$env = new Env(
new PrefixedVariableProvider(new EnvVariableProvider(), 'APP_'),
new PrefixedVariableProvider(new FileVariableProvider('/path/to/project/.env'), 'APP_'),
);
$env->get('VAR_1'); // returns 'value1'
$env->get('VAR_2'); // returns 'value2'
$env->get('VAR_3'); // returns 'value3'
$env->get('VAR_4'); // returns null
$env->get('VAR_5', 'defaultValue'); // returns 'defaultValue'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.