$_ENV in PHP is an array containing server-side environment variables. It is a super global variable in PHP and we can directly access it anywhere in the PHP program.
$_ENV just passively accepts server-side environment variables and converts them into array elements. You can try to output it directly.
When you want to see what is in a variable, there are three ways I know:
1、var_dump($_ENV); 2、print_r($_ENV); 3、foreach($_ENV as $key=>$val){echo $key.'--------'.$val.'<br>';}
Of these three ways, I think the first one is the most convenient. And the output content format is clear.
Since the $_ENV variable depends on the environment variable of the server, the results printed by the $_ENV variable obtained from different servers may be completely different. So it is not possible to list a complete list like $_SERVER. The following are the more common elements contained in the $_ENV array:
Sometimes, $_ENV will be empty. The reason is usually that the configuration item of the php configuration file php.ini is: variables_order = "GPCS". To make the value of $_ENV not empty, the value of variables_order should be added with a capital letter "E", that is: variables_order = "EGPCS".
The above configuration represents the source and order of external variables accepted by PHP. EGPCS is the abbreviation of Environment, Get, Post, Cookies, and Server. If E is missing from the configuration of variables_order, PHP cannot accept environment variables, and $_ENV will be empty.
Since turning on $_ENV, that is, variables_order = "EGPCS", will cause some performance losses, according to PHP officials, it is not recommended in production environments. They prefer to use the getenv (string $varname) function to obtain the value in Environment, and this needs to be noted when programming. If $_ENV is used during programming and variables_order is not configured as variables_order = "EGPCS", an error may be reported when the program is run.
Related recommendations:
Cause analysis php $_ENV is empty Reason analysis
##PHP server environment variable $_ENV
Confusion about variables $_SERVER, $_ENV and define defining system parameters
The above is the detailed content of Detailed explanation of $_ENV in PHP. For more information, please follow other related articles on the PHP Chinese website!