I made a php function that counts the weeks from now to 52 and then start from week 1 again to the left over weeks.
I wanna know if there is a easier way to do this, or that i made a proper function.
Here is my code:
function weeks($start_week)
{
$start_week = str_replace("0", "", $start_week); // from week 1 tot 9 remove the zero's.
$offset_week = $start_week - 1; // when the loop reach week 52, start with new weeks minus 1
$last_week = 52; // Last week of the year
$aantal_weken = 52; // # of weeks in a year
for($start_week; $start_week <= $aantal_weken; $start_week++)
{
echo $start_week.", ";
if($start_week == $last_week)
{
$new_weeks = 1; // when we reach week 52, set a new variable tot first week of the year
for($new_weeks; $new_weeks <= $offset_week; $new_weeks++)
{
echo $new_weeks.", ";
}
}
}
return $start_week;
}
$date = date("W");
weeks($date);
Output:
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 1, 2, 3,