我的代码就像这样
// $t = new ProjectProgressDao();
// $progressValues = $t->getRecords($projectId);
foreach ($progressValues as $Values) {
$weekStartingDays[$this->CalculateWeekStartDate($Values->getDate())] = $Values->getWorkCompleted();
}
基本上我想要的是???
Array
(
[a1]=>'k'
[a2]=>'a'
[a1]=>'w'
[a1]=>'z'
}
我想要
Array
(
[a1]=>'k+w+z'
[a3]=>'w'
[a4]=>'z'
)
a,b等是数值
答案 0 :(得分:1)
只需添加值,如果尚未设置,则将位置初始化为0:
foreach ($progressValues as $Values) {
if (!isset($weekStartingDays[$this->CalculateWeekStartDate($Values->getDate())])) {
$weekStartingDays[$this->CalculateWeekStartDate($Values->getDate())]=0;
}
$weekStartingDays[$this->CalculateWeekStartDate($Values->getDate())] += $Values->getWorkCompleted();
}