【发布时间】:2015-07-21 14:49:14
【问题描述】:
在下面的示例中,我正在遍历具有以下输出的 MySQL 查询的结果:
这是我目前拥有的 PHP:
foreach ($customers as $customer) {
if($customer['innumber'] != null){
$chartInbound['name'] = $customer['name'];
$chartInbound['label'] = $customer['innumber'];
$chartInbound['count'] = $customer['count'];
$chartInbound['customerid'] = $customer['id'];
array_push($out['chartInbound'], $chartInbound);
}
}
print_r($out['chartInbound']); 的输出为:
Array
(
[0] => Array
(
[name] => 1st Online Solutions
[label] => 01-02
[count] => 577
[customerid] => 129
)
[1] => Array
(
[name] => Bookngo
[label] => 01-02
[count] => 2
[customerid] => 95
)
[2] => Array
(
[name] => Boutixury
[label] => 07
[count] => 1
[customerid] => 14
)
[3] => Array
(
[name] => Cruise Village
[label] => 01-02
[count] => 16
[customerid] => 25
)
[4] => Array
(
[name] => Cruise Village
[label] => 00
[count] => 1
[customerid] => 25
)
[5] => Array
(
[customer] => Cruise Village
[label] => 07
[countInbound] => 16
[minsInbound] => 125
[customerid] => 25
)
...................
)
所需的输出应该是:
Array
(
[0] => Array
(
[name] => 1st Online Solutions
[01-02] => 577
[customerid] => 129
)
[1] => Array
(
[name] => Bookngo
[01-02] => 2
[customerid] => 95
)
[2] => Array
(
[name] => Boutixury
[07] => 1
[customerid] => 14
)
[3] => Array
(
[name] => Cruise Village
[07] => 16
[00] => 1
[01-02] => 16
[customerid] => 25
)
...................
)
我怎样才能达到上述结果?
【问题讨论】:
-
你应该根据需要生成数组。
-
@sgt BOSE:你能给我举个例子吗?