Jump to content

Repopulating an array after every 4 weeks


theknight

Recommended Posts

Here is my code:

 

<?php
//input will be start date

$startdate=0;
function getMondays($day,$month,$year,$i,$end){
    
$x = 7;
$add=0;
    
for($i; $i<$end; $i++){
$add++;
//This will get the first set of Mondays 
//store it inside an array
//time stamp 11 pm GMT on date
$array[$i] = date('U', mktime(0, 0, 0, $month, $day+$counter, $year));
//$firstDay = date('d/m/y', mktime(0, 0, 0, $month, 4+$counter, $year)); 
$counter = $x * $add;
}

return $array;
}

 

This gets the four weeks following the date set and store it in an array:

 

$Weeks = getMondays(04,04,2011,0,5);

 

Each slot is the equivalent of a week e.g. week 1, week 2, week 3, week 4,week 5

 

//perform equivilence test
if($week1==$currentdate || $currentdate<=$week2){
    
    //for all week 1 stick the following sentence
    echo "data for week 1";
    
}

if($currentdate>$week2 && $currentdate<=$week3){
    
    //for all week 2 stick the following sentence
    echo "data for week 2";
    
}

if($currentdate>$week3 && $currentdate<=$week4){
    
    //for all week 3 stick the following sentence
    echo "data for week 3";
    
}

if($currentdate>$week4 && $currentdate<=$week5){
    
    //for all week 4 stick the following sentence
    echo "data for week 3";
    
}

if($currentdate==$week5){
    
    //where d/m/y = the date on week 5.
   //will now become week 1 data
    getMondays(d,m,y,0,4);
    
}


 

Now depending on which week it is, a set data is displayed which is hardcoded.

 

Now what I want to do is to reset the array on week 4 (for the new month), without the array being repopulated with  the old date:

 

$Weeks = getMondays(04,04,2011,0,4);

 

everytime the script is run.

 

 

How do I do this?

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.