Possible Duplicate:
How to get most recent date from an array of dates?
I have a timetable which is an array:
array(
'01.01.2012|11:00',
'01.01.2012|14:30',
'01.01.2012|16:24', // example match
'01.01.2012|17:20',
'01.01.2012|17:43',
'02.01.2012|10:20',
'02.01.2012|12:30',
); // etc.
I want a Cron job that will check current date/time and compare to ones in array. First I check if the date is a match, that's no problem. But then I need to find and display the earliest time from that array which is after the current time. If there's no suitable time within the same date then I display the earliest time from the next date.
For example: lets take the array above and current date/time of 01.01.2012|14:45
- The date is a match so we continue
- The next time from the array 16:24, but how to find it using PHP? And if the current time is higher than anything for the same date in array, then get the earliest time from next date?
Obviously to get the string with correct date I use "foreach" and "if" and it returns fine. But then how do I go through the times?