xionhack Posted January 4, 2009 Share Posted January 4, 2009 Hello. I want to make a loop that will display tuesday, saturday, saturday, saturday, tuesday, saturday, saturday, saturday... etc, but with their exact dates. Let's say this week 1/6/2009, 1/10/2009, 1/10/2009, 1/10/2009, 1/13/2009, 1/17/2009, 1/17/2009, 1/17/2009.... etc, how can i do that?! Thanks Link to comment https://forums.phpfreaks.com/topic/139451-loop-of-tuesdays-and-saturdays/ Share on other sites More sharing options...
Clinton Posted January 4, 2009 Share Posted January 4, 2009 How long is this supposed to go on? Link to comment https://forums.phpfreaks.com/topic/139451-loop-of-tuesdays-and-saturdays/#findComment-729483 Share on other sites More sharing options...
xionhack Posted January 4, 2009 Author Share Posted January 4, 2009 Per month. All of the tuesdays and saturdays in the current month, and I want to make a button to move to the next month. Link to comment https://forums.phpfreaks.com/topic/139451-loop-of-tuesdays-and-saturdays/#findComment-729493 Share on other sites More sharing options...
kenrbnsn Posted January 4, 2009 Share Posted January 4, 2009 Here's one solution; <?php function getdays($start,$which) { $res = array(); $st = strtotime(date('Ym01',strtotime($start))); $end = strtotime('+1 month',$st); $fd = strtotime('first ' . $which,$st); for ($i = $fd;$i<$end; $i+=604800) $res[] = $i; return($res); } $days = array_merge(getdays('20090201','saturday'),getdays('20090201','tuesday')); sort($days); foreach($days as $d) echo date('l, F jS, Y',$d) . "\n"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/139451-loop-of-tuesdays-and-saturdays/#findComment-729528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.