What are the best practices for integrating PHP and CSS to change the background color of an HTML page?

To change the background color of an HTML page using PHP and CSS, you can echo out a style tag within the head section of your HTML document. This style tag will contain the CSS code to change the background color. You can use PHP to dynamically set the background color based on certain conditions or variables.

<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            background-color: <?php echo $background_color; ?>;
        }
    </style>
</head>
<body>
    <h1>Welcome to my website</h1>
    <p>This is a sample text.</p>
</body>
</html>