PHP code example of ndobromirov / php-env-dereference
1. Go to this page and download the library: Download ndobromirov/php-env-dereference 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/ */
ndobromirov / php-env-dereference example snippets
$a = 'hello';
$$a = 'world';
// Same output.
echo "$a ${$a}\n", "hello world\n";
// We have this environment variables.
putenv('MY_VAR_1=1');
putenv('MY_VAR_2=#MY_VAR_1');
putenv('MY_VAR_3=#MY_VAR_2');
putenv('MY_VAR_4=#MY_VAR_2 #MY_VAR_3');
// Simple dereferencing
echo EnvDereference\Variable::get('MY_VAR_3'); // Should output '#MY_VAR_1'.
echo EnvDereference\Variable::getRecursive('MY_VAR_3'); // Should output '1'.
// Multiple dereferencing
echo EnvDereference\Variable::getEmbedded('MY_VAR_4'); // Should output '#MY_VAR_1 #MY_VAR_2'.
echo EnvDereference\Variable::getEmbeddedRecursive('MY_VAR_4'); // Should output '1 1'.
// Provide defaultds for missing variables
echo EnvDereference\Variable::get('MY_MISSING_VAR', 'default'); // Should output 'default'.