如何按 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
)
)
我需要计算一个 houseid 的总价并做一些数学/条件,如果将这个数组分组会很容易......
我可以把这个数组格式化成类似的东西吗
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
)
)
或者任何人都可以建议我,如何循环原始数组来计算房子的总价格?