php使用多维数组按SUM分组
我有一个这样的PHP数组:
Array (
[0] => Array
(
[url_id] => 2191238
[time_spent] => 41
)
[1] => Array
(
[url_id] => 2191606
[time_spent] => 215
)
[2] => Array
(
[url_id] => 2191606
[time_spent] => 25
)
)
因此,如何time_spent
通过url_id 获取基于组的SUM(使用array_count_values)
回答:
为什么不更简单
$ts_by_url = array();foreach($array as $data) {
$ts_by_url[ $data['url_id'] ] += $data['time_spent'];
}
以上是 php使用多维数组按SUM分组 的全部内容, 来源链接: utcz.com/qa/404052.html