How can you improve the code provided to handle whitespace input more effectively in PHP?

The issue with the current code is that it does not handle whitespace input effectively. To improve this, we can trim the user input to remove any leading or trailing whitespace before comparing it to the correct answer. This ensures that whitespace does not affect the comparison result.

$userInput = trim($_POST['answer']); // Trim whitespace from user input
$correctAnswer = "apple"; // Correct answer without leading or trailing whitespace

if(strtolower($userInput) == $correctAnswer){
    echo "Correct!";
} else {
    echo "Incorrect!";
}