I have this code here...
$remaining = 0;
foreach($clientArrayInvoice as $key=>$row){
$remaining = $remaining + $row[\'total\'];
}
I am not sure what your question is exactly, but this would keep adding the absolute values if $remaining
is negative until it is positive again.
$remaining = $remaining + ($remaining < 0 && $row['remainingbalance'] < 0 ? -1 : 1) * $row['remainingbalance']);
This works for your example, it would be 0 - 51.75 + 17.85 = -33.9
. But I am not sure if it's the behavior you want in the bigger picture.