How to pull data from the API?

$curl =curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-football-v1.p.rapidapi.com/v2/leagues",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-rapidapi-host: api-football-v1.p.rapidapi.com",
"x-rapidapi-key: 3444c7f813mshf9250f3690d1a26p13dc53jsnd4589e46851a"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
With this code, to withdraw league_id country England ?
April 19th 20 at 12:10
1 answer
April 19th 20 at 12:12
Solution
$curl = curl_init();
 curl_setopt_array($curl, array(
 CURLOPT_URL => "https://api-football-v1.p.rapidapi.com/v2/leagues",
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_FOLLOWLOCATION => true,
 CURLOPT_ENCODING => "",
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 30,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => "GET",
 CURLOPT_HTTPHEADER => array(
 "x-rapidapi-host: api-football-v1.p.rapidapi.com",
 "x-rapidapi-key: 3444c7f813mshf9250f3690d1a26p13dc53jsnd4589e46851a"
),
));

 $response = curl_exec($curl);
 $err = curl_error($curl);

curl_close($curl);

 if ($err) {
 echo "cURL Error #:" . $err;
 } else {
 $response = json_decode($response);
 foreach ($response->api->leagues as $value) {
 if ($value->country == 'England') {
 echo $value->league_id;
}
}
 }
Why forice after you have written Responsa API -> League and then the valuy? - paris92 commented on April 19th 20 at 12:15
@paris92, 5e97390441955112122891.png
because the structure json'a - Eleanor commented on April 19th 20 at 12:18

Find more questions by tags APIPHP