How can PHP code be structured to display specific content based on user interaction?

To display specific content based on user interaction in PHP, you can use conditional statements such as if, else if, and else. By checking for certain conditions based on user input or interaction, you can determine which content to display on the webpage.

<?php
$user_input = $_POST['user_input'];

if ($user_input == 'option1') {
    echo "You selected Option 1";
} elseif ($user_input == 'option2') {
    echo "You selected Option 2";
} else {
    echo "Please select an option";
}
?>