How can the PHP function putenv() be used to set environment variables in a PHP application?

The PHP function putenv() can be used to set environment variables in a PHP application by providing the variable name and value as arguments to the function. This can be useful for configuring certain aspects of the application based on environment variables, such as database connection settings or API keys.

// Set environment variable
putenv("DB_HOST=localhost");
putenv("DB_USER=root");
putenv("DB_PASS=password");

// Retrieve environment variable
$dbHost = getenv("DB_HOST");
$dbUser = getenv("DB_USER");
$dbPass = getenv("DB_PASS");

// Use the variables in your application
echo "Database Host: " . $dbHost . "<br>";
echo "Database User: " . $dbUser . "<br>";
echo "Database Password: " . $dbPass . "<br>";