I'm new to PHP and have I problem right now. I want to make a file with bus times for a day, and want to show a user the nearest bus in the future. Every day there are just 15 buses, so it wouldnt be a big file. I thought about saving the file like this: 0120, 0230, 1020,1340 and so on. MY thinking right now is to read from this file by fgetcsv with a for loop and store all times in an array which are > than date("His"). This would happen in the controller. In my file which shows the output to the user I would then show the first element of the array in big font as the next bus and the next 10 elements in a smaller font. Would this work? I am not sure with my time format. Can I compare 0230 from a text file with the output from date()?
Thanks for your help!
Edit: Based on the comments below I tried this. Based on my understanding this should read in one element of the csv every iteration of the while loop, right?
<?php
$buses = 0;
$hoursMins = date("Gi");
$times = [];
if (($handle = fopen("1.csv", "r")) !== FALSE)
{
while (($element = fgetcsv($handle, 200, ",")) !== FALSE)
{
if($hoursMins < $element)
{
$times = $element;
echo $times[$buses++] . "<br />\n";
$buses++;
}
}
fclose($handle);
}
?>
This is only showing me 755 though.