I am trying to compact an expression of individual days into a shorter expression including hyphen-separate ranges.
Examples:
mon,tue,wed,thu,fri,sat
to be:mon-satmon,tue,wed,fri,sat
to bemon-wed,fri-sat
My coding attempt:
function dayrange($days){
$days = explode(",", str_replace(" ","",$days));
return reset($days) . "-" . end($days);
}
How can I shorten the multi-day expression so that consecutive days are merged into a range of days?
Basically, I would approach this by:
I wrote some code to do that: