[PHP] Build a query string from an array

Created on November 30, 2026

Use http_build_query() to URL-encode the keys and values of an array as pairs in a query string. This example includes an array of tags.

<?php

$params = [
    'name' => 'Tom',
    'age' => 20,
    'tags' => ['php', 'url'],
];

echo http_build_query($params);
name=Tom&age=20&tags%5B0%5D=php&tags%5B1%5D=url
PHP