【发布时间】:2018-09-12 02:47:14
【问题描述】:
我有一个用户通过自定义文件上传字段(高级自定义字段)从 Wordpress 后端上传一个 .csv 文件。然后我调用此字段从该文件中检索数据以创建所述数据的数组:
$upload_cq = get_field('report_current_quarter');
$report_cq = array();
if(($handle_cq = fopen($upload_cq, "r")) !== FALSE)
{
while(($data_cq = fgetcsv($handle_cq, 1000, ",")) !== FALSE)
{
$report_cq[] = $data_cq;
}
$results_cq = array_slice($report_cq, 3); // remove unwanted row
fclose($handle_cq);
}
创建数组后,我会创建另一个带有键和关联值的数组,并确保“team_id”列存在且不为空,因此(有一个我不会进入的 teamName 函数):
foreach($results_cq as $results)
{
$team_id = $results[6];
if(!empty($team_id))
{
$team_totals_cq[] = array(
'id' => $team_id,
'team' => teamName($team_id),
'total_volume' => $results[41],
'total_closed' => $results[24],
'listings_closed' => $results[22],
'buyers_closed' => $results[23],
'total_agc' => $results[29],
'rental_agc' => $results[30],
);
}
}
echo '<pre>'; print_r($team_totals_cq); echo '</pre>';
打印数组时,我得到以下信息。我现在的问题是;如何将结果与同一个团队“id”进行分组并将他们的结果相加(结果 = total_volume、total_closed、listings_closed、buyers_closed、total_agc 和 rent_agc):
Array
(
...
[6] => Array
(
[id] => 0011
[team] => Williamson Team
[total_volume] => $990,000
[total_closed] => 4
[listings_closed] => $0.00
[buyers_closed] => 1
[total_agc] => $20,812.50
[rental_agc] => $23,812.50
)
...
[9] => Array
(
[id] => 0011
[team] => Williamson Team
[total_volume] => $415,000
[total_closed] => 2
[listings_closed] => $0.00
[buyers_closed] => 0
[total_agc] => $12,450.00
[rental_agc] => $12,450.00
)
...
)
我在力所能及的范围内尝试了所有方法,但没有任何效果。
【问题讨论】:
-
我觉得这个问题太宽泛了,因为你没有展示任何研究证据,也没有尝试自我解决。我认为这个问题是一个任务请求;但是,SO 不是免费的代码编写服务。请在发布问题之前做更多事情。
标签: php arrays multidimensional-array