First Friday Calculation Explanation (of sorts)


	$d = getdate(mktime(1,1,1,$m,1,$y));  //the first of the month  
	$ff = (5 - $d["wday"] +7)%7+1;  //the first friday
    
Possible day of week that first of month could fall on $d["wday"] 5-$d["wday"]
See negative value
5 - $d["wday"] +7
No negative value
(5 - $d["wday"] +7)%7
Recovers previous non-negative values
(5 - $d["wday"] +7)%7+1
Sunday 0 5 12 5 6
Monday 1 4 11 4 5
Tuesday 2 3 10 3 4
Wednesday 3 2 9 2 3
Thursday 4 1 8 1 2
Friday 5 0 7 0 1
Saturday 6 -1 6 6 7

It could be done with a switch


    switch ($d["wday"]) {
     case 0:
         //first is Sunday
         $ff=6;
         break;
     case 1:
         //first is Monday
         $ff=5;
         break;
     case 2:
         //first is Tuesday
         $ff=4;
         break;
     case 3:
         //first is Wednesday
         $ff=3;
         break;
     case 4:
         //first is Thursday
         $ff=2;
         break;
     case 5:
         //first is Friday
         $ff=1;
         break;
     case 6:
         //first is Saturday
         $ff=7;
         break;
     default:
         //code to be executed if n is different from all labels;
 }