0, 'time_estimated' => 0, 'time_remaining' => 0, ); foreach ($subtasks as &$subtask) { $timesheet['time_estimated'] += $subtask['time_estimated']; $timesheet['time_spent'] += $subtask['time_spent']; } if ($timesheet['time_estimated'] == 0 && $timesheet['time_spent'] == 0) { $timesheet['time_estimated'] = $task['time_estimated']; $timesheet['time_spent'] = $task['time_spent']; } $timesheet['time_remaining'] = $timesheet['time_estimated'] - $timesheet['time_spent']; return $timesheet; } }