Signatur
http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $encoding_type = PHP_QUERY_RFC1738): string
Beschreibung
Nested Arrays werden zu key[subkey]=value. Für RFC 3986 (Leerzeichen als %20) den Encoding-Type auf PHP_QUERY_RFC3986 setzen.
Parameter
| Name | Typ | Default | Beschreibung |
|---|---|---|---|
| $data Pflicht | array|object | — | Query-Parameter. |
| $numeric_prefix | string | "" | Präfix für numerische Keys. |
| $arg_separator | ?string | null | Trenner (default &). |
| $encoding_type | int | PHP_QUERY_RFC1738 | Encoding-Standard. |
Rückgabewert
Typ
string
Beschreibung
Query-String.
Beispiele
Basis
<?php
$params = ['q' => 'php 8', 'page' => 2, 'tags' => ['syntax', 'oop']];
echo http_build_query($params, encoding_type: PHP_QUERY_RFC3986);
// q=php%208&page=2&tags%5B0%5D=syntax&tags%5B1%5D=oop