Answer the question
In order to leave comments, you need to log in
The problem with the calculation of the amount in the cycle, help me solve it?
There is a cycle, it contains the value (int) of the array cell from the database, but with each scrolling of the cycle, the value changes, the value has the same identifier in the array [“sum”], it is necessary to add the value of the previous scrolling of the cycle with the next one. I think it is necessary to resort to an array and write the value to a separate cell of the array
Answer the question
In order to leave comments, you need to log in
It is better to use sum()
in SQL query
Or otherwise
$sum_counter = ['total_sum' => 0];
foreach ($few_itteartion as $itearator_key => $some_ar) {
if (!isset($sum_counter['sum_for_ittaration'][$itearator_key]))
$sum_counter['sum_for_ittaration'][$itearator_key] = 0;
foreach ($some_ar as $v) {
$sum_counter['total_sum'] += $v['sum'];
$sum_counter['sum_for_ittaration'][$itearator_key] += $v['sum'];
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question