CKTIS / PHP
http_build_query()
Build a query from an array or public properties of an object.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $encoding_type = PHP_QUERY_RFC1738): stringBuild a query from an array or public properties of an object. Nested keys use bracket notation and null entries are omitted. A numeric prefix applies to top-level numeric keys. RFC 1738 uses plus for spaces while RFC 3986 uses %20. Supply the separator when the output must not depend on configuration.
Signature
http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $encoding_type = PHP_QUERY_RFC1738): string
Example output
n0=a+b&tag%5B0%5D=x%2By
n0=a%20b&tag%5B0%5D=x%2By
Examples
<?php
$data = [0=>"a b","tag"=>["x+y"],"empty"=>null];
echo http_build_query($data,"n","&",PHP_QUERY_RFC1738),PHP_EOL;
echo http_build_query($data,"n","&",PHP_QUERY_RFC3986);
Result
n0=a+b&tag%5B0%5D=x%2By n0=a%20b&tag%5B0%5D=x%2By