Answer the question
In order to leave comments, you need to log in
How to change json array?
Good day to all, there is a json array of type
"group": [
{
"id": "12",
"value": "3"
},
{
"id": "15",
"value": "1"
}
]
"group":
{
"12": "3",
"15": "1"
}
Answer the question
In order to leave comments, you need to log in
Don't thank:
$data = json_decode($json, true);
$data['group'] = array_reduce(
$data['group'],
function($res, $i) {
$res[$i['id']] = $i['value'];
return $res;
},
[]
);
{"group":{"12":"3","15":"1"}}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question