The following JSON structure:
{
"details":
[
{"specific_exercise.distance" : "14",},
{"specific_exercise.avg_pace" : "7.5"}
]
}
converts to this when using json_decode():
stdClass Object
(
[details] => Array
(
[0] => stdClass Object
(
[specific_exercise.distance] => 14
)
[1] => stdClass Object
(
[specific_exercise.avg_pace] => 7.5
)
)
)
Instead I’d like to have this converted into this:
stdClass Object
(
[details] => Array
(
[specific_exercise.distance] => 14
[specific_exercise.avg_pace] => 7.5
)
)
What’s the best way to convert from the json_decode() structure to the more effective PHP structure?
Changing your JSON probably will be better solution if you have control over that, for example
EDIT:
Then you can use this method:
You can further modify the method to work for each array not just details key.