From 371a09b6e9cbb6a4fd8a052c10f81694ce3e7aa2 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Wed, 21 Sep 2016 23:58:36 -0700 Subject: [PATCH] Fix #393: Add examples for POSTing data with and without indexes --- ..._values_same_key_with_indexes_explicit.php | 12 +++++++ ..._values_same_key_with_indexes_implicit.php | 14 +++++++++ ...ltiple_values_same_key_without_indexes.php | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 examples/post_multiple_values_same_key_with_indexes_explicit.php create mode 100644 examples/post_multiple_values_same_key_with_indexes_implicit.php create mode 100644 examples/post_multiple_values_same_key_without_indexes.php diff --git a/examples/post_multiple_values_same_key_with_indexes_explicit.php b/examples/post_multiple_values_same_key_with_indexes_explicit.php new file mode 100644 index 0000000..f5a6c0d --- /dev/null +++ b/examples/post_multiple_values_same_key_with_indexes_explicit.php @@ -0,0 +1,12 @@ +post('https://httpbin.org/post', array( + 'foo[0]' => 'bar', + 'foo[1]' => 'baz', +)); diff --git a/examples/post_multiple_values_same_key_with_indexes_implicit.php b/examples/post_multiple_values_same_key_with_indexes_implicit.php new file mode 100644 index 0000000..44c4570 --- /dev/null +++ b/examples/post_multiple_values_same_key_with_indexes_implicit.php @@ -0,0 +1,14 @@ +post('https://httpbin.org/post', array( + 'foo' => array( + 'bar', + 'baz', + ), +)); diff --git a/examples/post_multiple_values_same_key_without_indexes.php b/examples/post_multiple_values_same_key_without_indexes.php new file mode 100644 index 0000000..c3435b1 --- /dev/null +++ b/examples/post_multiple_values_same_key_without_indexes.php @@ -0,0 +1,31 @@ + $value) { + $key = rawurlencode($key); + if (is_array($value)) { + foreach ($value as $v) { + $v = rawurlencode($v); + $array[] = $key . '=' . $v; + } + } else { + $value = rawurlencode($value); + $array[] = $key . '=' . $value; + } + } + return implode('&', $array); +} + +$curl = new Curl(); +$curl->post('https://httpbin.org/post', http_build_query_without_indexes(array( + 'foo' => array( + 'bar', + 'baz', + ), +)));