How can you send a generated GET request using the GuzzleHttp library in which one of the parameters must be a one-dimensional array (without indexes)

Those. The parameters in the GET request should be: opt=1¶m[]=val1¶m[]=val2

 $client = new \GuzzleHttp\Client()->get('https://www.url.com/api', [ 'form_params' => [ 'opt' => 1, 'param' => ['val1', 'val2'], ] ]); 

GuzzleHttp uses the function of forming the GET string http_build_query() which the nested array is indexed by force. The result is the following query:
opt=1¶m[1]=val1¶m[2]=val2

    2 answers 2

    Since Guzzle supports passing a simple string to the query parameter, the only option is to form the query yourself. Those. something like

     $client = (new \GuzzleHttp\Client())->get( 'https://www.url.com/api', [ 'query' => 'opt=1&param[]=' . implode('&param[]=', ['val1', 'val2']) ] ); 
    • Thanks, earned! - Chaikin Evgenii
     $client->get('http://example.com', ['query' => ['param1' => 'value1']]); 
    • Well, this is not what a questioner needs - Oleg Lobach