Home >Backend Development >PHP Tutorial >beautiful goodbye A problem with http_build_query in php
When we use CURL to post data, we need to set the post data
curl_setopt($c, CURLOPT_POSTFIELDS, $post_data);
If the $data here is
Copy the code The code is as follows:
$data = array(
'name'=>'scofield',
'time'=>'2012-2-3'
)
Copy code The code is as follows:
function getStr($array,$Separator='&') {
if (empty($array))
return;
if (!is_array($array)) {
return $array;
}
$returnStr = '';
foreach ($array as $key => $val) {
$temp = '';
if (is_array($val)) {
for ( $i = 0; $i < count($val); $i++) {
$returnStr .= $key . '[' . $i . ']' . '=' . $val[$i] . $ Separator;
}
} else {
$returnStr.= $key . '=' . $val . $Separator;
}
}
$returnStr = substr(trim($returnStr), 0, -1);
return $returnStr;
}
The above introduces a problem of http_build_query in beautiful goodbye php, including the content of beautiful goodbye. I hope it will be helpful to friends who are interested in PHP tutorials.