Jump to content

Loop of tuesdays and saturdays


xionhack

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.