Timeword - compress an array of days and represent it as a set of ranges

StackOverflow https://stackoverflow.com/questions/5944472

  •  31-10-2019
  •  | 
  •  

Pregunta

I am trying to make a function that will take this input: mon,tue,wed,thu,fri,sat

and spit out this: mon-sat

At the moment, i'm using this.

function dayrange($days){
   $days = explode(",", str_replace(" ","",$days));
   return reset($days) . "-" . end($days);
}

Okay now for the curve ball, I want the function to also work if I give it this string: mon,tue,wed,fri,sat

It needs to skip thursday and say something like: mon-wed, fri-sat

Can I get recommendations on the best way to do that? I'm using PHP, so answers in php are great, but psuedo code is fine too.

Cheers

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top