getenv

PHP 4, PHP 5, PHP 7, PHP 8
getenv - Gets the value of an environment variable
Manual
Code Examples

getenv( string$varname, [bool$local_only = false] ): string|false
arraygetenv

Parameters

varname

The variable name.

local_only

Set to true to only return local environment variables (set by the operating system or putenv).

Return Values

Returns the value of the environment variable varname, or false if the environment variable varname does not exist. If varname is omitted, all environment variables are returned as associative array.

Notes

Warning:

If PHP is running in a SAPI such as Fast CGI, this function will always return the value of an environment variable set by the SAPI, even if putenv has been used to set a local environment variable of the same name. Use the local_only parameter to return the value of locally-set environment variables.

Changelog

Version Description
7.1.0 The varname can now be omitted to retrieve an associative array of all environment variables.
7.0.9 The local_only parameter has been added.

Related Functions

Example of getenv

Show all examples for getenv

PHP Version:


Function getenv:

PHP Options and Information Functions

Most used PHP functions