I have set up a .env file to hold my environmental variables. If I var_dump($_ENV), it shows all of my key pairs just as they are in my .env file so I know that PHP is seeing the environmental variables correctly. But if I echo out a getenv of one of the environmental variables, I get an empty string.
$port = $_ENV["DATABASE_PORT"];
echo $port // echos out 3306
This displays the correct port of 3306
$port = getenv("DATABASE_PORT");
echo $port // echos out an empty string
This displays nothing, just an empty string
Any thoughts as to why the $_ENV is getting populated, but getenv won't pull a value?
My Answer:
't return any value because the environment variable "Won" is not set in the current environment.
Rate this post
3 of 5 based on 5822 votesComments