更好用http_build_query
<?php
$data = array('foo'=>'bar',
'baz'=>'boom',
'cow'=>'milk',
'php'=>'hypertext processor');
echo http_build_query($data) . "\n";
// Output : foo=bar&baz=boom&cow=milk&php=hypertext+processor
echo http_build_query($data, '', '&');
// Ouput: foo=bar&baz=boom&cow=milk&php=hypertext+processor
?>
http://php.net/manual/en/function.http-build-query.php
使用foreach
循环(不推荐)
<?php
$ar_qs = array();
foreach ($data as $key => $value) {
$ar_qs[] = "$key=". urlencode($value);
}
echo $query_string = implode("&", $ar_qs);
?>