【发布时间】:2022-01-02 20:54:54
【问题描述】:
我是 PHP 新手。我想从网站 API 导出一些数据,我有带有查询和 JSON 响应的脚本,但是有大约 20 个类似的查询,我想我可以通过循环使这个脚本更简单,但真的不知道如何去做。我还想将结果插入到表格中。
示例:
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.opensea.io/api/v1/collection/clonex');
$json = $response->getBody();
$data = json_decode($json);
print "CloneX: ";
print_r($data->collection->stats->floor_price);
$client2 = new \GuzzleHttp\Client();
$response2 = $client2->request('GET', 'https://api.opensea.io/api/v1/collection/the-solaverse-sola-stars');
$json2 = $response2->getBody();
$data2 = json_decode($json2);
print "<br />SolaVerse: ";
print_r($data2->collection->stats->floor_price);
【问题讨论】: