Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

$_ENV

The $_ENV variable is a special superglobal variable that is used to retrieve the environment values.

The $_ENV variable is an associative array where the keys are the global variables and the values are the corresponding values.

$_ENV is a superglobal: it is always available, in every scope.

Values inside $_ENV are always strings.

The values in the $_ENV are collected at the start of the script, and do not change during the lifetime of the script. To get an up-to-date value, the function getenv() is preferable.

The content of the $_ENV array varies from installation to installation: there is no default list of keys in that array. It entirely depends on the underlying system.

<?php

    // Displays the name of the user
    echo $_ENV['USER'];

    print_r($_ENV);
    // Results is similar to this 
    /**
    Array
    (
        [TERM] => xterm
        [PATH] => /usr/bin:/bin
        [LANG] => C
        [SHELL] => /bin/sh
        [MAIL] => /var/mail/nobody
        [LOGNAME] => nobody
        [USER] => nobody
        [HOME] => /tmp
    )
    */

?>

Documentation

See Also