I cannot get the two-dimensional array of the API post request. Unable to formulate logic in php to get multiple arrays from JSON format API. The structure of the JSON API request is:
"abc": [{"id": 123, "days": [{"a": 11, "b": 11},{"a":22, "b":22}]} , {"id": 456, "days": [{"a": 33, "b": 33},{"a":44, "b":44}]}
I'm trying this logic for a 2D array to get the ID and the values of A,B which I know are not in the correct format.
foreach ($request->abc as $ids => $id) { foreach ($id => array_combine($a, $b)) { $value .= $this->helper($id, $a, $b); } }
I have successfully retrieved a single array from the API via this loop:
// single array structure from post request "abc": {"single_array_val":[11,12,13,14,15]} foreach ($request->abc as $single_arrays => $single_array) { $value .= $this->helper($single_arrays, $single_array); }
Through this loop, I called the object of "abc":
Then I called the helper function in which I developed a loop for the "days" object:
This is the helper2 function where I decode the values of a and b by sending them as arguments:
Now I can easily pass the values of a and b as parameters to the helper2 function. Hope someone will find it helpful.