PHP 调用 API

问题描述 投票:0回答:1

早上好,

我在回显变量时遇到小问题。也许你可以帮助我。谢谢! https://api.openligadb.de/index.html

/getmatchdata/matchid

这有效:

<?php echo $match["team1"]["teamIconUrl"]; ?>

但是我无法获得比赛结果。

<?php echo $match["matchResults"]["pointsTeam1"]; ?>



<?php


// Retrieve the data for the current matchday from the OpenLigaDB API
$url = sprintf("https://api.openligadb.de/getmatchdata/bl1", $current);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);
 
if ($output === false) {
    die("Error when requesting the API: " . curl_error($ch));
}

curl_close($ch);

// Decoding the API response
$matches = json_decode($output, true);

if ($matches === null) {
    die("Error processing API response: " . json_last_error_msg());
}
?>
php api
1个回答
0
投票

像这样打印

<?php echo $match["matchResults"][0]["pointsTeam1"]; ?>
© www.soinside.com 2019 - 2024. All rights reserved.