I have an array of cronjobs on my server, which I need to sort by the date they fire, the starting array is:
Array (
[0] => 00 08 24 10 * 2012 curl --user user:pass command
[1] => 00 09 24 10 * 2012 curl --user user:pass command
[2] => 00 08 18 10 * 2012 curl --user user:pass command
[3] => 00 11 18 10 * 2012 curl --user user:pass command
)
I want this list represented in a table on my website, but sorted by month, day of month, hour, minute.
The desired output is:
Array(
[0] => 00 08 18 10 * 2012 curl --user user:pass command
[1] => 00 11 18 10 * 2012 curl --user user:pass command
[2] => 00 08 24 10 * 2012 curl --user user:pass command
[3] => 00 09 24 10 * 2012 curl --user user:pass command
Can anyone point me in the direction I need to go in order to achieve this?
Thanks for your time.
How about this?
What I’ve done here is basically extracting all the numeric parts from all the strings in question, then reversing them into a numeric string, then comparing these strings.
This can be modified in two ways: first, hardening the regex so it won’t match numbers in command itself:
… and second, using a memoizing function:
Here I removed the rest of the string with
substring; it’s more efficient, I think. Still, showing how this can be done with regex might be useful as well. ))