Browse Source

added support in nested arrays for bash examples

Eric Schricker 2 years ago
parent
commit
7e052d8fb5
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/Tools/WritingUtils.php

+ 8 - 1
src/Tools/WritingUtils.php

@@ -57,7 +57,14 @@ class WritingUtils
                 } else {
                 } else {
                     // Hash query param (eg filter[name]=john should become "filter[name]": "john")
                     // Hash query param (eg filter[name]=john should become "filter[name]": "john")
                     foreach ($value as $item => $itemValue) {
                     foreach ($value as $item => $itemValue) {
-                        $qs .= "$paramName" . '[' . urlencode($item) . ']=' . urlencode($itemValue) . '&';
+                        if (is_array($itemValue)) {
+                            // Handle arrays (eg filter[category][]=1&filter[category][]=5 should become filter[category]: [1,5])
+                            foreach ($itemValue as $itemValueEntry) {
+                                $qs .= "$paramName" . '[' . urlencode($item) . '][]=' . urlencode($itemValueEntry) . '&';
+                            }
+                        } else {
+                            $qs .= "$paramName" . '[' . urlencode($item) . ']=' . urlencode($itemValue) . '&';
+                        }
                     }
                     }
                 }
                 }
             }
             }