$tmp = [];
$tmp['id'] = 'aaa';
$tmp['name'] = 'bbb';
$tmp['vvvv'] = [
'www'=>1,
'ffff'=>2
];
echo (json_encode($tmp));
The output is
{
"id": "aaa",
"name": "bbb",
"vvvv": {
"www": 1,
"ffff": 2
}
}
I would like to ask how to change the output to
{
"id": "aaa",
"name": "bbb",
"vvvv": [
{"www": 1},
{"ffff": 2}
]
}
I have tested that this works, but it is not very easy to use:
$tmp['vvvv'] = [
0=>(object)['www'=>1],
1=>(object)['fff'=>2]
];
Just replace the elements in $tmp['vvvv'] with an array. There is no need to convert them into objects, as follows
That’s how it is, all PHP is map