首先上数组
Array
(
[0] => Array
(
[tid] => 12
[aid] => 1
[openid] => oWWUP0dieOLSHl3CzjyHIcIsadhtVo
[nickname] => 帅锅你好帅
[sales] =>
[team_name] => 帅
[team_slogan] => 酷
[title] => 测试活动
[new] => Array
(
[0] => Array
(
[id] => 1
[openid] => oWWUP0dieOLSHl3CzjyHIcIsadhtVo
[nickname] => 帅锅你好帅
[tid] => 12
[cre_time] => 1512704950
[aid] => 0
[sales] => 12
)
[1] => Array
(
[id] => 3
[openid] => oWWUP0UXRfKKA6imX_X-6OU7OKv0
[nickname] => landy
[tid] => 12
[cre_time] => 1512704975
[aid] => 0
[sales] => 54
)
)
)
[1] => Array
(
[tid] => 13
[aid] => 2
[openid] => oWWUP0dieOLSHl3CzjyHIcIsadhtVo
[nickname] => 帅锅你好帅
[sales] =>
[team_name] => 帅
[team_slogan] => 酷
[title] => 测按时
[new] => Array
(
[0] => Array
(
[id] => 2
[openid] => oWWUP0dieOLSHl3CzjyHIcIsadhtVo
[nickname] => 帅锅你好帅
[tid] => 13
[cre_time] => 1512704970
[aid] => 2
[sales] => 24
)
)
)
)
我想计算
[0][new][sales]的总和
[1][new][sales]的总和
我不知道数组到底会有多大的....所以.....
我就知道我需要..new 下 tid 相同的话,sales 求和
求大家帮帮忙吧!~~我菜鸟...
?!
3 回答
拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
foreach ($data as $key => $value) {
$data[$key]['sum'] = array_sum(array_column($value['new'], 'sales'));
}
不知道是不是你要的结果,其实这种直接通过数据库查询更好计算吧
- 3 回答
- 0 关注
- 361 浏览
添加回答
举报
0/150
提交
取消