File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -84,12 +84,15 @@ function close() {
84
84
function http_build_multi_query ($ data , $ key =NULL ) {
85
85
$ query = array ();
86
86
87
+ $ is_array_assoc = is_array_assoc ($ data );
88
+
87
89
foreach ($ data as $ k => $ value ) {
88
90
if (is_string ($ value )) {
89
- $ query [] = urlencode (is_null ($ key ) ? $ k : $ key ) . '= ' . rawurlencode ($ value );
91
+ $ brackets = $ is_array_assoc ? '[ ' . $ k . '] ' : '[] ' ;
92
+ $ query [] = urlencode (is_null ($ key ) ? $ k : $ key . $ brackets ) . '= ' . rawurlencode ($ value );
90
93
}
91
94
else if (is_array ($ value )) {
92
- $ query [] = $ this ->http_build_multi_query ($ value , $ k . ' [] ' );
95
+ $ query [] = $ this ->http_build_multi_query ($ value , $ k );
93
96
}
94
97
}
95
98
Original file line number Diff line number Diff line change @@ -59,6 +59,20 @@ public function testPostData() {
59
59
)) === 'post ' );
60
60
}
61
61
62
+ public function testPostAssociativeArrayData () {
63
+ $ test = new Test ();
64
+ $ this ->assertTrue ($ test ->server ('POST ' , array (
65
+ 'test ' => 'post_multidimensional ' ,
66
+ 'username ' => 'myusername ' ,
67
+ 'password ' => 'mypassword ' ,
68
+ 'more_data ' => array (
69
+ 'param1 ' => 'something ' ,
70
+ 'param2 ' => 'other thing ' ,
71
+ 'param3 ' => '123 ' ,
72
+ ),
73
+ )) === 'test=post_multidimensional&username=myusername&password=mypassword&more_data%5Bparam1%5D=something&more_data%5Bparam2%5D=other%20thing&more_data%5Bparam3%5D=123 ' );
74
+ }
75
+
62
76
public function testPostMultidimensionalData () {
63
77
$ test = new Test ();
64
78
$ this ->assertTrue ($ test ->server ('POST ' , array (
You can’t perform that action at this time.
0 commit comments