How can the issue of displaying variable names instead of values in URLs be resolved when generating links dynamically in PHP?

When generating links dynamically in PHP, the issue of displaying variable names instead of values in URLs can be resolved by using the `http_build_query` function to properly encode the query string parameters. This function will convert an array of key-value pairs into a URL-encoded query string, ensuring that the values are displayed in the URL instead of the variable names.

<?php
// Define the variables
$id = 123;
$name = "John Doe";

// Create an array of key-value pairs
$params = array(
    'id' => $id,
    'name' => $name
);

// Generate the URL with properly encoded query string parameters
$url = 'http://example.com?' . http_build_query($params);

// Output the generated URL
echo $url;
?>