Php 从多个json数组URL获取值

Php 从多个json数组URL获取值,php,arrays,loops,curl,foreach,Php,Arrays,Loops,Curl,Foreach,我需要从外部项API json数组中获取[result]->[data]->[id]->xx信息。我想将它们保存在mysql表(items)中 第一个json数组的url示例: 您可以在url中看到[1,]。这是我要从这里开始获取的最小项目ID 一个json数组url最多可以显示1000个项目。API有超过170.000个项目,我需要它们的特定[数据][id]。API调用限制为每秒100次和每小时36.000次 我的想法是从当前数组中获取最后一个[data][id]值。然后在下一个循环中,我将

我需要从外部项API json数组中获取[result]->[data]->[id]->xx信息。我想将它们保存在mysql表(items)中

第一个json数组的url示例:

您可以在url中看到[1,]。这是我要从这里开始获取的最小项目ID

一个json数组url最多可以显示1000个项目。API有超过170.000个项目,我需要它们的特定[数据][id]。API调用限制为每秒100次和每小时36.000次

我的想法是从当前数组中获取最后一个[data][id]值。然后在下一个循环中,我将1添加到最后一个数组´[data][id]值中,作为下一个循环的起点。等等

在示例url中,最后一个项目id是2429。因此,在下一个循环中,2430将是起点。

这是我的密码。我不知道如何循环这个问题,也不知道这是否可行。也许有一个更容易的解决办法

 //**Decode JSON in PHP ARRAY**//

function getSslPage($url, $userAgent)
{
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    $result = curl_exec($ch);
    curl_close($ch);

    return json_decode($result, true);
}

$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';

//**GET the [DATA] [ID] value of the last KEY in the CURRENT array**//

$all_values = array_values($data['results']);
$last_value = end($all_values);

//**In the next LOOP the [DATA] [ID] VALUE should be +1 as the new starting point**//

$startingItem = $last_value['data']['id'] + 1;

$url = "https://eu.api.blizzard.com/data/wow/search/item?namespace=static-eu&orderby=id&_pageSize=1000&id=[$startingItem,]&_page=1&locale=de_DE&access_token=USPqoKWmdURvO1mmDeW5vRghI5dojO13XZ";

$data = getSslPage($url, $userAgent);

//** INSERT in database **//

foreach ($data['results'] as $entry) {

       $sqle= "REPLACE INTO `items`
                (`id`)
            VALUES
                ('{$entry['data']['id']}')";
}

如果您使用的是PHP版本>7.3,那么可以使用

顺便说一下,您正在使用

end($all\u值)

注意该索引末尾的逗号(,),您应该将索引字符串设置为仅包含数字,然后使用

$newkey=trim($key,,)

然后可以使用

$intnewkey=intval($newkey)

现在,您可以使用

$intnewkey++,

返回字符串

$newIndex=strval($intnewkey)

然后再次将逗号附加到API调用的新值:

$newIndexForAPI=$newIndex.,'