I have the following array values,
[
{
"amount": 4.27,
"month": 1,
"year": 2017
},
{
"amount": 2.46,
"month": 1,
"year": 2017
},
{
"amount": 1.5,
"month": 2,
"year": 2017
},
{
"amount": 28.24,
"month": 2,
"year": 2017
},
{
"amount": 8.24,
"month": 3,
"year": 2017
},
{
"amount": 3.65,
"month": 3,
"year": 2017
},
{
"amount": 0.86,
"month": 3,
"year": 2017
},
{
"amount": 0,
"month": 1,
"year": 2018
},
{
"amount": 71.84,
"month": 2,
"year": 2018
},
{
"amount": 26.62,
"month": 3,
"year": 2018
}]
that has to be grouped with respect to specific month and year and the final values should be in the following format,
[
{
"amount": 6.63,
"month": 1,
"year": 2017
},
{
"amount": 29.74,
"month": 2,
"year": 2017
},
{
"amount":12.75,
"month": 3,
"year": 2017
},
{
"amount": 0,
"month": 1,
"year": 2018
},
{
"amount": 71.84,
"month": 2,
"year": 2018
},
{
"amount": 26.62,
"month": 3,
"year": 2018
}]
I have referred this example : Group array items using object
But I cant sort out the summing up part and all I get is only the first value from a particular month and year.