我遇到了如何将子值移动到父级中的问题。第一个和第二个循环是OK。但是在第三个循环中,请注意第三个循环中包含有人名的数组[0]。我有这个数组结构:
Array
(
[TSK LEMPOR] => Array
(
[SAMSUL HADI] => Array
(
[0] => SAMSUL HADI
[1] => 156
[2] => 204
)
[HELMI ALMASAKTI] => Array
(
[0] => HELMI ALMASAKTI
[1] => 156
[2] => 204
)
)
)
它假设是这样的:
Array
(
[TSK LEMPOR] => Array
(
[SAMSUL HADI] => Array
(
[0] => 156
[1] => 204
)
[HELMI ALMASAKTI] => Array
(
[0] => 156
[1] => 204
)
)
)
从此代码生成:
$attendance = array();
foreach($projects as $project) {
$workers = DB::table('tk_worker')
->where('w_id', $project->tkat_wid)
->select('w_id','w_name')
->get();
foreach($workers as $worker) {
$attendance[$project->plpr_description][$worker->w_name]['a'] = $worker->w_name;
$activities = DB::table('tk_attendance')
->where('tkat_projectid',$project->plpr_projectid)
->where('tkat_wid',$worker->w_id)
->groupby('tkat_activityid')->get();
foreach($activities as $activity) {
$attendance[$project->plpr_description][$worker->w_name][] = $activity->tkat_activityid;
}
}
}
所以请帮助我。