php function gen offset do url https api vk com method wall get domain

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?php
function gen()
{
$offset = 0;
do {
$url = "https://api.vk.com/method/wall.get?domain=glory_to_ukraine01&offset={$offset}&count=100&filter=all";
$response = json_decode(file_get_contents($url), true);
$all = array_shift($response['response']);
foreach ($response['response'] as $item) {
++$offset;
yield $item['likes']['count'];
}
} while($offset < $all);
}
$summa = 0;
foreach (gen() as $v) {
$summa += $v;
}
echo 'summa = ', $summa, PHP_EOL;