PHP URLs Build an URL-encoded query string from an array

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


The http_build_query() will create a query string from an array or object. These strings can be appended to a URL to create a GET request, or used in a POST request with, for example, cURL.

$parameters = array(
    'parameter1' => 'foo',
    'parameter2' => 'bar',
$queryString = http_build_query($parameters);

$queryString will have the following value:


http_build_query() will also work with multi-dimensional arrays:

$parameters = array(
    "parameter3" => array(
        "sub1" => "foo",
        "sub2" => "bar",
    "parameter4" => "baz",
$queryString = http_build_query($parameters);

$queryString will have this value:


which is the URL-encoded version of


Got any PHP Question?