【发布时间】:2022-06-10 22:51:26
【问题描述】:
我正在尝试使用 foreach 循环一组固定装置,这工作正常。但是我想从fixtures循环中选择{fixtuteID}并将它放在预测api端点中
对灯具的 API 调用
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-football-v1.p.rapidapi.com/v3/fixtures?date=2xx1-06-10&timezone=XXXXX",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'x-rapidapi-key: XxXxXxXxXxXxXxXxXxXxXxXx',
'x-rapidapi-host: xvvvxxx.io'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
predictions 的 API 调用需要上面的 {fixtuteID}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-football-v1.p.rapidapi.com/v3/predictions?fixture={fixtuteID}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'x-rapidapi-key: XxXxXxXxXxXxXxXxXxXxXxXx',
'x-rapidapi-host: xvvvxxx.io'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
下面是我想要的循环。
fixture 1 和 prediction-fixture 1
fixture 2 和 prediction-fixture 2
fixture 3 和 prediction-fixture 3
fixture 4 和 prediction-fixture 4
end loop
【问题讨论】:
-
请显示当前循环代码,以便我们了解从哪里开始。目前,这有点脱离上下文,不清楚为什么不能将夹具 ID 传递给另一个 cURL 调用。