If I understand you correctly, $costs is an array of cost sets, which are arrays of costs, and you want the totals for each set. That would mean you need something like:
foreach($costs as $cost_set) {
$amount = 0;
foreach ($cost_set as $cost) {
$amount += $cost['amount_set'];
}
$amounts[] = $amount;
}
That will give yo an array of subtotals based on the groups of costs.