Ive connected to an API named transportapi. Ive stored the results into a variable and decoded them to JSON. Im able to print out the first line of result but i wish to print them all out using some kind of loop.
here is my attempt
$url="https://transportapi.com/v3/uk/train/station/eus/2018-04-15/13:38/timetable.json?app_id=*****&app_key=*****&destination=LIV&train_status=passenger";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_HEADER, 0);
$response = curl_exec($curl);
curl_close($curl);
$datas = json_decode($response);
echo $datas[0]->station_name;
foreach ($datas as $data) {
echo $data->station_name . '<br>';
}
?>
if i use echo $data->date;
that only prints out the first result. but i need all of the results. Any help with the correct syntax would be much appreciated :)