You don’t need to change the query. Just change the foreach loop code.
foreach($Monthly_details as $key){
if(empty($fetch[$key->project_code])){
$fetch[$key->project_code]['total'] = 0;
}
$fetch[$key->project_code]['total'] += ($key->daily_rate * $key->days) - $key->absent - $key->late - $key->ut;
}
return $fetch;
// The Section which calls the function show().
$results = work($id);
foreach($results as $projectCode => $total){
echo $projectCode." total cost is: ".$total;
}
CLICK HERE to find out more related problems solutions.