Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

getenv

Description

The getenv of Options / Information for PHP gets the value of an environment variable.

Syntax

getenv(string $varname, bool $local_only = false): string|false
getenv(): array

Parameters

varname

The variable name.

local_only

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

Return

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.

Examples

1 · void

<?

$return = getenv();

print_r($return);

?>
Array
(
    [PATH] => /usr/local/bin:/bin:/usr/bin
)

2 · varname

<?

$varname = 'PATH';

$return = getenv($varname);

echo $return;

?>
/usr/local/bin:/bin:/usr/bin

3 · local_only

<?

$varname = 'PATH';
$local_only = true;

$return = getenv($varname, $local_only);

echo $return;

?>
/usr/local/bin:/bin:/usr/bin

4 · Superglobal

<?

$varname = 'PATH';

$return = $_SERVER[$varname];

echo $return;

?>
/usr/local/bin:/bin:/usr/bin
HomeMenu