"accounts" => array:6 [
0 => array:2 [
"acc_id" => 1
"balance" => 1000.00
]
1 => array:2 [
"acc_id" => 2
"balance" => -1500.00
]
2 => array:4 [
"acc_id" => 3
"balance" => 5000.00
]
]
Hi, How could I sum up all the balance correct?
Code
foreach ($y['accounts'] as $k)
{
$sum_balance = $k['balance'];
}
$sum_balance += $sum_balance;
With this code, The result will only sum the last balance itself. Example result is 10000.00