http_build_query函数用于将数组或对象转换为URL编码的查询字符串。
它的用法如下:
string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )参数说明:
query_data: 要转换的数组或对象。numeric_prefix (可选): 数组键名的数字前缀。arg_separator (可选): 参数之间的分隔符,默认为’&'。enc_type (可选): URL编码类型,默认为PHP_QUERY_RFC1738。示例:
$data = array( 'name' => 'John', 'age' => 30, 'email' => 'john@example.com');$queryString = http_build_query($data);echo $queryString; // 输出:name=John&age=30&email=john%40example.com在上面的示例中,将数组$data转换为URL编码的查询字符串。如果想要在URL中传递数组,可以在数组键名后面加上[],如’name[]',这样在服务器端可以接收到一个名为name的数组。


