How can the & symbol be used as a "normal" character in a URL with a GET query in PHP?

When using the & symbol as a "normal" character in a URL with a GET query in PHP, it needs to be properly encoded as %26 to avoid conflicts with separating query parameters. This can be achieved using the urlencode() function in PHP.

$query_param = "value1";
$encoded_ampersand = urlencode("&");
$query_string = "param1=" . $query_param . "%26param2=" . $encoded_ampersand;
echo "http://example.com/script.php?" . $query_string;