What are best practices for handling query strings in PHP to ensure the desired output in the $_GET array?

When handling query strings in PHP, it is important to properly sanitize and validate the input to ensure the desired output in the $_GET array. One best practice is to use the filter_input() function to retrieve and filter input from the $_GET array, which helps prevent security vulnerabilities such as SQL injection or cross-site scripting attacks.

// Example of handling query strings in PHP using filter_input()
$queryParam = filter_input(INPUT_GET, 'param', FILTER_SANITIZE_STRING);
if($queryParam){
    // Use the sanitized $queryParam in your code
} else {
    // Handle the case where the parameter is not present or invalid
}