$array = array('username' => 'mainytype','password' => 'abc1234','phone' => '7023451287');
$count = 0;
foreach($array as $k => $v){
$count++;
$new_data['info'.$count] = array("input[$k]=".$v);
}
print_r($new_data);
$ty = http_build_query($new_data);
print_r($ty);
?>
// print_r($new_data):
Array ( [info1] => Array ( [0] => input[username]=mainytype ) [info2] => Array ( [0] => input[password]=abc1234 ) [info3] => Array ( [0] => input[phone]=7023452134 ) )
//print_r($ty);
info1%5B0%5D=input%5Busername%5D%3Dmainytype&info2%5B0%5D=input%5Bpassword %5D%3Dabc1234&info3%5B0%5D=input%5Bphone%5D%3D7023452134
我猜这foreach
会构建 3 个分离的数组。我理解 的结果 http_build_query()
,但我希望它看起来像这样:
input%5Busername%5D=mainytype&input%5Bpassword%5D=abc1234&input%5Bphone%5D=7023451287