I am using the code below to echo the current month. How can i enhance it so that is shows all the months with the names and days and dates..
Code:
&
Try this:
function getDates($year)
{
$dates = array();
date("L", mktime(0,0,0, 7,7, $year)) ? $days = 366 : $days = 365;
for($i = 1; $i <= $days; $i++){
$month = date('m', mktime(0,0,0,1,$i,$year));
$wk = date('W', mktime(0,0,0,1,$i,$year));
$wkDay = date('D', mktime(0,0,0,1,$i,$year));
$day = date('d', mktime(0,0,0,1,$i,$year));
$dates[$month][$wk][$wkDay] = $day;
}
return $dates;
}
it will return an array of months->weeks->day->weekday of the year you pass to the function. Hopefully it should be easy to traverse through the array to print everything out. Am sure there are a lot of tweaks you can make to that but its a start.
I would also try and stay away from printing out html using echo, for example instead of;
echo '';
for($i=1;$i<$firstDay['wday'];$i++){
echo ' ';
}
do;
;
It kind of makes the code more readable I think.
EDIT: Just thought I should include an example of a use case as well, as below:
$weeks) { ?>
', $weekdays); ?>
$days){ ?>
Which gives you the output:
- 热议问题