_http_build_query()
From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
String. The query string.
Usage
_http_build_query( $data, $prefix, $sep, $key, $urlencode );
- $data(array|object) (required)
- An array or object of data. Converted to array.
- $prefix(string)
- Numeric index. If set, start parameter numbering with it.
Default:null - $sep(string)
- Argument separator; defaults to
'arg_separator.output'.
Default:null - $key(string)
- Used to prefix key name.
Default:empty string - $urlencode(true|false)
- Whether to use urlencode() in the result.
Default:true
Notes
Changelog
| Since 3.2.0 | Introduced. |
_http_build_query() http build query code WP 7.0
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 );
}