Depends on what the $cost var looks like inside the foreach loop. Assuming it is something like '5' (number in a string), it'll probably go something like this:
$totalCost = 0;
foreach($request['cost'] as $cost){
$totalCost += $cost;
}
Then the total cost would be available in the $totalCost variable. You may also want to check each $cost variable before adding it to the sum to make sure it is a number like:
foreach($request['cost'] as $cost){
if (is_numeric($cost)) {
$totalCost += $cost;
}
}