_http_build_query

函数


_http_build_query ( $data, $prefix = null, $sep = null, $key = '', $urlencode = true )
Access
Private
参数
  • (array|object)
    $data
    An array or object of data. Converted to array.
    Required:
  • (string)
    $prefix
    Optional. Numeric index. If set, start parameter numbering with it. Default null.
    Required:
    Default: null
  • (string)
    $sep
    Optional. Argument separator; defaults to ‘arg_separator.output’. Default null.
    Required:
    Default: null
  • (string)
    $key
    Optional. Used to prefix key name. Default empty.
    Required:
    Default: (empty)
  • (bool)
    $urlencode
    Optional. Whether to use urlencode() in the result. Default true.
    Required:
    Default: true
返回值
  • (string) The query string.
相关
  • https://www.php.net/manual/en/function.http-build-query.php
定义位置
  • wp-includes/functions.php
    , line 1058
引入
3.2.0
弃用

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

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 );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。