I would need to insert an associative array into my existing code, to make an HTTP request.
My code at the moment:
$payload =[
'method_id' => 2,
'api_key' => 5,
];
$res = $client->post('some.website', [,
'form_params' => [
foreach($this->payload as $key => $s_key) {
$key => $s_key;
}
],
]);
How to make now sure, each element of the $payload array is inserted into the form_params array?
I tried using:
foreach ($this->payload as $s_key => $key) {
//?!
}
But I don't know how to proceed inside the form_params element?
Using the payload array directly inside form elements is resulting into this:
"form_params" => [
0 => array:2 [
"method_id" => 2
"api_key" => 5
]
]
What I would need is something like this:
"form_params" => [
"method_id" => 2
"api_key" => 5
]
'form_params' => $payload
, since it already is an associated array?[▼ "form_params" => array:1 [▼ 0 => array:2 [▼ "method_id" => 2 "api_key" => 5 ] ] ]
$payload
doesn't actually look like you're showing or if you did something like'form_params' => [$payload]
(which is not what I suggested). Demo: 3v4l.org/ohCsW'some.website', [,
. It should be'some.website', [