PHP code example of tekintian / phpenv

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

    

tekintian / phpenv example snippets



use tekintian\phpenv\Env;

if (!function_exists('env')) {
	/**
	 * Gets the value of an environment variable.
	 *
	 * @param  string  $key
	 * @param  mixed  $default
	 * @return mixed
	 */
	function env($key, $default = null) {
		return Env::get($key, $default);
	}

  
// composer自动加载
fine('ROOT_PATH', dirname(__DIR__));

// 加载helper函数
 '.env');
  
// 使用助手函数获取环境配置
// $app_url = env("APP_URL", "");

// 直接使用Env对象获取配置
$app_url = Env::get("APP_URL", "未知");
  
echo sprintf("Env环境变量<br>APP_URL=%s <br>APP_NAME=%s", $app_url, env('APP_NAME'));

~~~



helper/helper.php 文件

~~~php


use tekintian\phpenv\Env;

if (!function_exists('env')) {
	/**
	 * Gets the value of an environment variable.
	 *
	 * @param  string  $key
	 * @param  mixed  $default
	 * @return mixed
	 */
	function env($key, $default = null) {
		return Env::get($key, $default);
	}