How can constants be used effectively in PHP scripts to handle different environments (e.g., Windows vs. Linux) and streamline file path management?

When dealing with different environments in PHP scripts, constants can be used to define file paths and configurations that vary between environments, such as Windows and Linux. By setting up constants for these paths, you can easily switch between environments without having to manually update file paths throughout the codebase. This can streamline file path management and make your code more portable and maintainable.

// Define constants for file paths based on the environment
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    define('ROOT_PATH', 'C:/xampp/htdocs/project/');
} else {
    define('ROOT_PATH', '/var/www/html/project/');
}

// Usage example
require_once(ROOT_PATH . 'config/config.php');
require_once(ROOT_PATH . 'includes/functions.php');