Get environment value in controller

To get an environment value in a PHP controller, you can use the getenv function. For example, to get the value of the APP_ENV environment variable, you would do the following:

$appEnv = getenv('APP_ENV');

This will return the value of the APP_ENV environment variable as a string.

Watch a course Learn object oriented PHP

You can also use the $_ENV superglobal to get environment variables. For example:

$appEnv = $_ENV['APP_ENV'];

The $_ENV superglobal is an array that contains all environment variables as elements.

Note that environment variables are specific to the environment in which a PHP script is executed, and are often used to configure PHP scripts for different environments (e.g. development, staging, production). They can be set in the system environment, or in a file such as .env in the root of your project.