Sorting an array of weekday names
If you convert the day to a number 0-6 you can array_shift
and array_push
that many times to move the previous days to the end of the array.
Try using uksort()
. You can compare dates in the callback function described in the link.
For example:
function compare($a, $b) {
date(strtotime($a)) - date(strtotime($b));
}
uksort($array, "compare");
Here's proof of it working
You can get the day of the week via the date function. Sunday is 0, Monday is 1, and so forth.
$weekday = date("w");
Then, I suggest using the uksort function to sort the array relative to its keys, which takes a callback function as a sorting guideline.
uksort($schedules, function ($a, $b) use ($weekday) {
// convert each day to a number 0-6 and compare to $weekday
});