I am trying to come up with the most efficient and best way to accomplish this somewhat of a complex situation. I know that I could build this solution using probably around 5 if else statements, maybe more - however there must be a better way to accomplish what I want to.
So here's what I am trying to do. I have an events page on my website, and what I want to do is display the dates in a minimalistic way when possible. What I mean is the following:
Say I have 3 dates: May 5
, May 6
, May 7
. I want to display it as: May 5 - 7
.
However, there will be situations where the dates may be: May 5
, May 7
. In this case I would like to display it as: May 5 & 7
.
However, there may also be situations where the dates may be: May 25
, June 2
. In this case I would like to display it as: May 25
& June 2
.
However! There also may be situations where the dates may be: May 25
, May 26
, June 2
. In this case it should display as: May 25 - 26 & June 2
Of course, there could just be a single date as well. But one other thing, it could be possible that there could be more than 3 dates as well, so it would be nice if it could work regardless of how many dates there are (IE loop through an array).
I know that we are suppose to make an attempt and show some code to debug, however I don't even know where to start with this, if this is too much for someone to put together - just giving me an idea of how to do something like this efficiently would be a huge help.
Thanks