http_build_query的使用方法
string http_build_query ( mixed $query_data
[, string $numeric_prefix
[, string $arg_separator
[, int $enc_type
=PHP_QUERY_RFC1738
]]] )
使用给出的关联(或下标)数组生成一个URL-eccode请求的字符串
使用方法:
$data = array('foo'=>'bar', 'baz'=>'boom', 'cow'=>'milk', 'php'=>'hypertext processor'); echo http_build_query($data) . "\n"; echo http_build_query($data, '', '&');
//会输出:
foo=bar&baz=boom&cow=milk&php=hypertext+processor
foo=bar&baz=boom&cow=milk&php=hypertext+processor
如果数组不带key,则以下标的默认数字下标作为生成的URL-encode的key:
$data = array('foo', 'bar', 'baz', 'boom', 'cow' => 'milk', 'php' =>'hypertext processor'); echo http_build_query($data) . "\n"; echo http_build_query($data, 'myvar_'); //输出 0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor
更多的用法请参见:http://www.php.net/manual/zh/function.http-build-query.php