R
R
RamPM2018-03-11 21:11:03
PHP
RamPM, 2018-03-11 21:11:03

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

1 answer(s)
B
berzhikeev, 2018-03-12
@berzhikeev

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 question

Ask a Question

731 491 924 answers to any question