What are the potential pitfalls of manually appending multiple variables to a URL in PHP?

Appending multiple variables to a URL manually in PHP can lead to errors and messy code. It is prone to mistakes such as missing ampersands (&) between variables or incorrectly encoding special characters. To solve this issue, you can use the `http_build_query()` function in PHP, which takes an associative array of parameters and constructs a URL-encoded query string.

// Define an associative array of parameters
$params = array(
    'variable1' => 'value1',
    'variable2' => 'value2',
    'variable3' => 'value3'
);

// Build the query string
$queryString = http_build_query($params);

// Append the query string to the base URL
$url = 'https://example.com/page.php?' . $queryString;

echo $url;