What are the best practices for handling user input from dropdown lists in PHP to prevent security vulnerabilities?

When handling user input from dropdown lists in PHP, it is important to validate and sanitize the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One way to do this is by using PHP's filter_input function with the FILTER_SANITIZE_STRING filter to sanitize the input before using it in your application.

// Retrieve and sanitize user input from a dropdown list
$user_input = filter_input(INPUT_POST, 'dropdown_input', FILTER_SANITIZE_STRING);

// Use the sanitized input in your application
if ($user_input) {
    // Process the input
} else {
    // Handle invalid input
}