Y
Y
yischyk2019-08-04 16:26:51
PHP
yischyk, 2019-08-04 16:26:51

How to sum duplicate array values?

$vk_stats = json_decode(file_get_contents('https://api.vk.com/method/stats.get?group_id='.$_GET['id'].'&stats_groups=reach&interval=day&intervals_count=14&extended=0&access_token='.$token.'&v='.$v), true);
 foreach ($vk_stats['response'] as $vk_stats_res) {



    $summ+= $vk_stats_res['reach'];
    echo $summ;

}

how to get sum of ["reach"] values

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2019-08-04
@yischyk

If you output one array (arr), where is the totality of these arrays (item), then something like this:

$summ = 0;
foreach ($arr as $item) {
    $summ+= $item['reach'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question