I have created a loop which will display date 2004 to 2014 in a formatted way. But the problem is, it is showing 204 instead of 2004 and continue this till 209.. So, how to show
You could do it also with a (Quite) different Structure:
$yrMax) {
return true;
}
else {
displayMonth($yr);
$yr++;
return displayDate($yr, $yrMax);
}
}
function displayMonth($yr, $month = 1) {
if ($month > 12) {
return true;
}
else {
displayDay($yr, $month);
return displayMonth($yr, $month+1);
}
}
function displayDay($yr, $month, $day = 1, $dayMax = 31) {
if ($day > $dayMax) {
return true;
} else {
$displayMonth = getMonth($month);
echo "$day $displayMonth $yr
";
$day++;
return displayDay($yr, $month, $day, $dayMax);
}
}
function getMonth($month) {
switch($month){
case 1:
return 'Jan';
case 2:
return 'Feb';
case 3:
return 'Mar';
case 4:
return 'Apr';
case 5:
return 'May';
case 6:
return 'Jun';
case 7:
return 'Jul';
case 8:
return 'Aug';
case 9:
return 'Sep';
case 10:
return 'Oct';
case 11:
return 'Nov';
case 12:
return 'Dec';
}
}
//Here we call the structure build above.
if (displayDate(2004, 2014)) {
echo 'Done';
}
?>