PHP code example of melbahja / environ

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

    

melbahja / environ example snippets




use Melbahja\Environ\Environ;

// environ looking for .env or env.ini file in your directory
Environ::load('/path/to/your/project');

var_dump(Environ::get('APP_MODE')); // string

var_dump(Environ::get('DATABASE')); // array

var_dump($_ENV['DATABASE']); // array


  # if you want a helper
  function env(string $var, $default = null)
  {
    return \Melbahja\Environ\Environ::get($var, $default);
  }

Environ::load(string $directory): bool

Environ::get(string $var, $default = null): mixed

Environ::set(string $var, $value): bool

# Example: Environ::is('apache'), Environ::is('cli')
Environ::is(string $sapi): bool
ini

; set a var
APP_MODE = "dev"

; array
[DATABASE]
HOST = '127.0.0.1'
USERNAME = 'root'
PASSWORD = null