What are best practices for handling URL parameters and accessing corresponding values in PHP arrays?

When handling URL parameters in PHP, it is important to properly sanitize and validate the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One common way to access URL parameters is by using the $_GET superglobal array, which contains key-value pairs of all the parameters passed in the URL.

// Example of accessing URL parameters in PHP
if(isset($_GET['param1'])) {
    $param1 = $_GET['param1'];
    
    // Sanitize and validate the parameter if needed
    $param1 = filter_var($param1, FILTER_SANITIZE_STRING);
    
    // Use the sanitized parameter in your code
    echo "Parameter 1: " . $param1;
}