PHP to populate drop down list with specific dates
I'm looking to populate a drop down list in a form with dates of the next 4 Fridays and Saturdays. This is for a reservation system of sorts. I'm thinking I should be using the strtotime
function.
However, I'd like to order this drop down menu so that if the user tries the operation on a Saturday, the first saturday option is displayed first.
I was thinking of populating the menu with
strtotime('friday');
st开发者_如何学Crtotime('saturday');
strtotime('+1 weeks friday');
strtotime('+1 weeks saturday');
strtotime('+2 weeks friday');
strtotime('+2 weeks saturday');
strtotime('+3 weeks friday');
strtotime('+3 weeks saturday');
but obviously this wouldn't work if used it on a Saturday. (i.e. next friday which is next week will be displayed above the current saturday). Can anyone suggest a way to get around this?
Sorry if that question is rambling but it's been a long day :p
EDIT: To clarify, I'm looking for a way to automagically change the list ordering to
strtotime('saturday');
strtotime('+1 weeks friday');
strtotime('+1 weeks saturday');
strtotime('+2 weeks friday');
strtotime('+2 weeks saturday');
strtotime('+3 weeks friday');
strtotime('+3 weeks saturday');
strtotime('+4 weeks friday');
if the user runs the script on a saturday. (i.e. maintain 8 items in the list with the first one being the next available date).
I assume this string is getting passed to strtotime()?
Don't use "next friday" and "next saturday". Saying "next friday" always gets you the next Friday after today. Just use "friday" instead, it returns the same as "today" if today is Friday, otherwise it returns the same as "next friday".
To get the next four Fridays and Saturdays do this:
strtotime('friday');
strtotime('saturday');
strtotime('+1 weeks friday');
strtotime('+1 weeks saturday');
strtotime('+2 weeks friday');
strtotime('+2 weeks saturday');
strtotime('+3 weeks friday');
strtotime('+3 weeks saturday');
精彩评论