Is there a way to build a query automatically with http_build_query
using parameters with the same name?
If I do something like
array('foo' => 'x', 'foo' => 'y');
They are obviously overwritten within the array, but even if I do:
array('foo' => array('x', 'y'));
The function creates something like foo[0]=x&foo[1]
, which isn't what I want, since I need the parameters in this format foo=x&foo=y
.
Here is a function I created to build the query and preserve names. I created this to work with a third-party API that requires multiple query string parameters with the same name.
Usage:
Outputs:
This should do what you want, I had an api that required the same thing.