php num 100 result array numdoc 10 for limit numdoc page floor numdoc

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
$num = 100;
$result = array();
$numdoc = 10;
for ($i = 0; $i < $limit; $i += $numdoc) {
$page = floor($i / $numdoc) + 1;
$params = array(
'query' => $keyword,
'numdoc' => 10,
'page' => $page
);
$url = "http://api.pr-cy.ru:80/realtime/google/serp?" . http_build_query($params);
$json = $this->http->get($url);
$data = json_decode($json, true);
if (!$data) {
break;
}
$result += $data['serp'];
}
foreach ($result as $key => $value) {
$result[$key]['position'] = $key + 1;
}
return $result;