How can PHP be used to dynamically change the color of a navigation link based on user interaction?

To dynamically change the color of a navigation link based on user interaction, you can use PHP in combination with HTML and CSS. One way to achieve this is by using PHP to check for a specific condition, such as a user being logged in, and then outputting different CSS classes accordingly.

<?php
// Check if user is logged in
if($loggedIn) {
    $colorClass = "logged-in-color";
} else {
    $colorClass = "logged-out-color";
}
?>

<!DOCTYPE html>
<html>
<head>
    <style>
        .logged-in-color {
            color: blue;
        }
        .logged-out-color {
            color: red;
        }
    </style>
</head>
<body>
    <nav>
        <a href="#" class="<?php echo $colorClass; ?>">Home</a>
    </nav>
</body>
</html>