PHP, alternating weeks logic

php

I need to write some code in PHP that performs an action only on alternating weeks, based on the day of the week (mon, tue etc) rather than the number (1st, 7th etc).

So on a cycle starting on a Monday it should run for one week then not the following week.

I am sure this must be easier than I think but can't seem to work it out, so help please!

Best Solution

You could simply take the week number, and perform your action when it is odd (or even!), if the day is monday, for example:

$time=time();
$dayNo=strftime('%u', $time);  #1=monday
$weekNo=strftime('%U', $time); #week number

if (($dayNo==1) && ($weekNo%2))
{
   #do something on mondays, alternating weeks
}