Before the loop, add a line that says
$totalprofit = 0;
Inside the loop, after you've assigned a value to
$profit_foreach_group, add a line
$totalprofit += $profit_foreach_group;
Echo that variable at the end of the loop.
Or, if you want to create an array for some reason, change your line to
$profit_foreach_group = $subtotal_profit - $supplier_shipping_cost;
which will add a new element to the array each time the loop iterates. You can then sum the array at the end of the loop. Not sure it makes it any easier, and you can't
echo $profit_foreach_group if you make it into an array.