【发布时间】:2015-06-25 13:15:25
【问题描述】:
我正在遍历两个存储过程的结果集,根据另一个存储过程中的字段在一个存储过程中获取结果。
包含结果集的两个数组是$customers 和$subcustomers。
foreach($customers as $customer)
{
foreach($subcustomers as $subcustomer)
{
if($subcustomer['parent'] == $customer['id'])
{
if($customer['innumber'] == null && $subcustomer['innumber'] != null)
{
$chartInboundSub['name'] = $customer['name'];
$chartInboundSub['label'] = $subcustomer['innumber'];
$chartInboundSub['countInbound'] = $customer['count'];
$chartInboundSub['minsInbound'] = ceil($customer['duration'] / 60);
$chartInboundSub['customerid'] = $customer['id'];
array_push($out['chartInbound'], $chartInboundSub);
}
}
}
}
print_r($out['chartInbound'])的当前输出如下:
Array
(
[0] => Array
(
[countInbound] => 426
[minsInbound] => 340
[name] => Telekomm
[label] => 01-02
[customerid] => 6
)
[1] => Array
(
[countInbound] => 1
[minsInbound] => 2
[name] => Telekomm
[label] => 01-02
[customerid] => 6
)
[2] => Array
(
[countInbound] => 3
[minsInbound] => 21
[name] => Telekomm
[label] => 080
[customerid] => 6
)
[3] => Array
(
[countInbound] => 1920
[minsInbound] => 15766
[name] => Telekomm
[label] => 084
[customerid] => 6
)
[4] => Array
(
[countInbound] => 2332
[minsInbound] => 17521
[name] => Telekomm
[label] => 084
[customerid] => 6
)
...
)
以上结果需要name、label、customerid与countInbound和minsInbound相加,所以:
期望的输出应该是:
Array
(
[0] => Array
(
[countInbound] => 427
[minsInbound] => 342
[name] => Telekomm
[label] => 01-02
[customerid] => 6
)
[1] => Array
(
[countInbound] => 3
[minsInbound] => 21
[name] => Telekomm
[label] => 080
[customerid] => 6
)
[2] => Array
(
[countInbound] => 4252
[minsInbound] => 33287
[name] => Telekomm
[label] => 084
[customerid] => 6
)
...
)
【问题讨论】:
-
抱歉,我不太明白,如果 name、label 和 customerid 相同,您想将
countInbound和minsInbound相加吗? -
@PHPeter:是的,没错