How can PHP be used to write CSS styles based on specific conditions using if-else statements?

To write CSS styles based on specific conditions using if-else statements in PHP, you can output dynamic CSS code within the HTML document. By using PHP to generate CSS styles, you can apply different styles based on certain conditions or variables in your application.

<?php
header("Content-type: text/css");

$color = "red";

if ($color == "red") {
    echo "body { background-color: red; }";
} else {
    echo "body { background-color: blue; }";
}
?>