A WordPress-centric search engine for devs and theme authors



_http_build_query ›

Since3.2.0
Deprecatedn/a
_http_build_query ( $data, $prefix = null, $sep = null, $key = '', $urlencode = true )
Access:
  • private
Parameters: (5)
  • (array|object) $data An array or object of data. Converted to array.
    Required: Yes
  • (string) $prefix Optional. Numeric index. If set, start parameter numbering with it. Default null.
    Required: No
    Default: null
  • (string) $sep Optional. Argument separator; defaults to 'arg_separator.output'. Default null.
    Required: No
    Default: null
  • (string) $key Optional. Used to prefix key name. Default empty.
    Required: No
    Default: (empty)
  • (bool) $urlencode Optional. Whether to use urlencode() in the result. Default true.
    Required: No
    Default: true
See:
Returns:
  • (string) The query string.
Defined at:
Codex:

From php.net (modified by Mark Jaquith to behave like the native PHP5 function).



Source

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 ) && $prefix != null ) {
			$k = $prefix . $k;
		}
		if ( ! empty( $key ) ) {
			$k = $key . '%5B' . $k . '%5D';
		}
		if ( $v === null ) {
			continue;
		} elseif ( $v === false ) {
			$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 );
}