How can PHP code be optimized to accurately display information based on a user-inputted number of days?

When displaying information based on a user-inputted number of days in PHP, it is important to ensure that the input is properly sanitized and validated to prevent any potential security risks. One way to optimize the code is to use a conditional statement to check if the input is a valid number of days before processing and displaying the information.

<?php
// Validate user input for number of days
$days = isset($_GET['days']) ? intval($_GET['days']) : 0;

if ($days > 0) {
    // Display information based on the user-inputted number of days
    echo "Displaying information for $days days.";
} else {
    echo "Please enter a valid number of days.";
}
?>