How is it possible to generate an array of array of objects where they are grouped based on the object property 'name'? I can do this in Javascript but not sure how to accomplish this in PHP.
Here is an example snippet of the current json_encoded echo output:
[
{"id":14970,
"amount":"70",
"name":"Food"
},
{"id":14970,
"amount":"100",
"name":"Drink"
},
{"id":14970,
"amount":"100",
"name":"Food"
},
{"id":14970,
"amount":"300",
"name":"Drink"
},
{"id":14970,
"amount":"10",
"name":"Taxi"
},
{"id":14970,
"amount":"200",
"name":"Food"
}
]
Here would be the desired output:
[
[
{"id":14970,
"amount":"70",
"name":"Food"
},
{"id":14970,
"amount":"100",
"name":"Food"
},
{"id":14970,
"amount":"200",
"name":"Food"
}
],
[
{"id":14970,
"amount":"100",
"name":"Drink"
},
{"id":14970,
"amount":"300",
"name":"Drink"
}
],
[
{"id":14970,
"amount":"10",
"name":"Taxi"
}
]
]
Would be very grateful if the solution is explained as my knowledge on PHP is limited and would love to learn how this works for future reference and usage of PHP.