How can I group this array by houseid ?
Array
(
[0] => stdClass Object
(
[id] => 1111
[houseid] => 58
[price] => 2995
)
[1] => stdClass Object
(
[id] => 1112
[houseid] => 58
[price] => 4050
)
[2] => stdClass Object
(
[id] => 1114
[houseid] => 60
[price] => 1695
)
[3] => stdClass Object
(
[id] => 1115
[houseid] => 60
[price] => 2250
)
[4] => stdClass Object
(
[id] => 1116
[houseid] => 60
[price] => 2295
)
)
i need to calculate the total price for a houseid and do some math/conditions, it would be easy if the group this array…
can i format this array to something like
Array
(
[58] => stdClass Object(
[0] => stdClass Object
(
[id] => 1111
[price] => 2995
)
[1] => stdClass Object
(
[id] => 1112
[houseid] => 58
[price] => 4050
)
)
[60] => stdClass Object(
[0] => stdClass Object(
[id] => 1114
[price] => 1695
)
[1] => stdClass Object
(
[id] => 1115
[price] => 2250
)
[2] => stdClass Object
(
[id] => 1116
[price] => 2295
)
)
Or else can anyone suggest me, how to loop the original array to count the total price for a house ?
You can use
array_reduceOutput
Full live Demo