I'm fetching an api that collects the number of infected people to display on the web page which can be displayed on the web page as an array but is unable to fetch some variables to display one by one. from being unable to extract the data to the end
$api = file_get_contents("https://covid19.ddc.moph.go.th/api/Cases/today-cases-all");
$data = json_decode($api, true);
print_r($data);
result :
Array (
[0] => Array (
[txn_date] => 2022-01-17
[new_case] => 6929
[total_case] => 2331414
[new_case_excludeabroad] => 6720
[total_case_excludeabroad] => 2318971
[new_death] => 13
[total_death] => 21938
[new_recovered] => 5255
[total_recovered] => 2227485
[update_date] => 2022-01-17 07:23:11
)
)
If you want to take some value how to write ?
I would use a forach-loop to display the data here:
foreach ($data as $row) {
echo $row[txn_date];
}
Instead of echo, you could use whatever you want to display the data, you could also add them to another variable or add html-tags around:
foreach ($data as $row) {
$html = '<li>'.$row[txn_date].'</li>';
}