I'm using the below code to output train departure times. But I can't get them sorted by time of departure. I'm new to coding so not sure how to solve this. How can I use natural-sort or some other solution to get this sorted?
<?php
$url = 'http://api.sl.se/api2/realtimedepartures.json?key=xxxx&siteid=9192&timewindow=30';
$jsondata = file_get_contents($url);
$json = json_decode($jsondata,true);
foreach ($json['ResponseData']['Metros'] as $metro) {
if ($metro['DisplayTime'] != "Nu") {
$output .= "<ul><li><strong>".$metro['DisplayTime'].".</strong> </li>";
} else {
$output .= "<ul><li><strong>".$metro['DisplayTime']." avgår </strong></li>";
}
$output .= "<li>".$metro['GroupOfLine']."</li>";
$output .= "<li> nr ".$metro['LineNumber']." </li>";
$output .= "<li> till<strong> ".$metro['SafeDestinationName']."</strong></li></ul>";
}
echo $output;
?>
Example of the output can be viewed at http://beta.tunnelbanakarta.se/slussen