How can PHP handle different cases or scenarios when searching for a user in a file, such as displaying an error message or showing an image?

When searching for a user in a file, PHP can handle different cases or scenarios by using conditional statements. For example, if the user is not found in the file, PHP can display an error message. If the user is found, PHP can display relevant information or even show an image associated with the user.

// Search for a user in a file
$user = "John Doe";
$users = file("users.txt", FILE_IGNORE_NEW_LINES);

if (in_array($user, $users)) {
    // User found, display user information or show an image
    echo "User found: $user";
    // Display image
    echo "<img src='images/$user.jpg' alt='$user'>";
} else {
    // User not found, display error message
    echo "User not found";
}