当前位置:Gxlcms > PHP教程 > 数组针对某项的求和有关问题

数组针对某项的求和有关问题

时间:2021-07-01 10:21:17 帮助过:2人阅读

数组针对某项的求和问题
已知数组a:

array (
0 =>
array (
'stock_no' => 'SU13080800340',
'adress' => 'B',
'arr_time' => '2013-08-14 09:00:00',
'c_type' => 'P32E',
'cust_no' => '310F61VA5A',
'mount_total' => '1',
'total' => '16',
'c1_time' => '2013-08-10 15:00:00',
'packageno' => 'CVT121015001',
),
1 =>
array (
'stock_no' => 'SU13080800340',
'adress' => 'B',
'arr_time' => '2013-08-14 09:00:00',
'c_type' => 'P32E',
'cust_no' => '310F61VA5B',
'mount_total' => '2',
'total' => '32',
'c1_time' => '2013-08-10 15:00:00',
'packageno' => 'CVT121015002',
),
2 =>
array (
'stock_no' => 'SU13080800340',
'adress' => 'B',
'arr_time' => '2013-08-14 09:00:00',
'c_type' => 'P32E',
'cust_no' => '310F61VA5B',
'mount_total' => '2',
'total' => '32',
'c1_time' => '2013-08-10 15:00:00',
'packageno' => 'CVT121226001',
),
)


如何分别求得数组中的项cust_no对应的packageno的结果以及stock_no对应mount_total和total项求和的结果?
假设cust_no为310F61VA5A时,对应的packageno为CVT121225001。
cust_no为310F61VA5B时,对应的packageno为CVT121225002,CVT121226001。

stock_no为SU13080800340时,求得的mount_total结果为3(1+2),total结果为48(16+32)。

如何达到这样的效果?

分享到:

人气教程排行