On this page
_http_build_query( array|object $data, string $prefix = null, string $sep = null, string $key = '', bool $urlencode = true ): string
This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use https://www.php.net/manual/en/function.http-build-query.php instead.
From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
Description
See also
Parameters
$dataarray|object Required-
An array or object of data. Converted to array.
$prefixstring Optional-
Numeric index. If set, start parameter numbering with it.
Default:
null $sepstring Optional-
Argument separator; defaults to
'arg_separator.output'.
Default:
null $keystring Optional-
Used to prefix key name.
Default:
'' $urlencodebool Optional-
Whether to use urlencode() in the result.
Default:
true
Return
string The query string.
Source
File: wp-includes/functions.php. View all references
function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) {
$ret = array();
foreach ( (array) $data as $k => $v ) {
if ( $urlencode ) {
$k = urlencode( $k );
}
if ( is_int( $k ) && null != $prefix ) {
$k = $prefix . $k;
}
if ( ! empty( $key ) ) {
$k = $key . '%5B' . $k . '%5D';
}
if ( null === $v ) {
continue;
} elseif ( false === $v ) {
$v = '0';
}
if ( is_array( $v ) || is_object( $v ) ) {
array_push( $ret, _http_build_query( $v, '', $sep, $k, $urlencode ) );
} elseif ( $urlencode ) {
array_push( $ret, $k . '=' . urlencode( $v ) );
} else {
array_push( $ret, $k . '=' . $v );
}
}
if ( null === $sep ) {
$sep = ini_get( 'arg_separator.output' );
}
return implode( $sep, $ret );
}
Related
Uses
| Uses | Description |
|---|---|
| _http_build_query() wp-includes/functions.php | From php.net (modified by Mark Jaquith to behave like the native PHP5 function). |
Used By
| Used By | Description |
|---|---|
| build_query() wp-includes/functions.php | Builds URL query based on an associative and, or indexed array. |
| _http_build_query() wp-includes/functions.php | From php.net (modified by Mark Jaquith to behave like the native PHP5 function). |
Changelog
| Version | Description |
|---|---|
| 3.2.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_http_build_query