How can PHP be used to control the output of images based on user input?

To control the output of images based on user input in PHP, you can use conditional statements to determine which image to display based on the user's input. This can be achieved by using a form to capture user input and then processing that input to determine the appropriate image to display.

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

if ($userInput == 'option1') {
    echo '<img src="image1.jpg" alt="Image 1">';
} elseif ($userInput == 'option2') {
    echo '<img src="image2.jpg" alt="Image 2">';
} else {
    echo 'Invalid input';
}
?>