for ($y = 25; $y >= 7; $y--)
{
$showYear = false;
for ($m = 12; $m >= 1; $m--)
{
if (blogList($m, $y))
$showYear = true;
}
if ($showYear) {
echo '<h2>' . (2000 + $y) . '</h2>';
for ($m = 12; $m >= 1; $m--)
{
echo blogList($m, $y);
}
}
}
//blog archives
function blogList($month, $year)
{
$lastDate = array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$beginDate = mkTime(0, 0, 0, $month, 1, $year);
$endDate = mkTime(0, 0, 0, $month, $l开发者_StackOverflow社区astDate[$month - 1], $year);
$query = .......;
}
- i don't know why he set the
$y=25
.$showYear = false;
- why the
$lastDate = array(31,29,31,30,31,30,31,31,30,31,30,31);
?
$y = 25
is because he's looping backwards from 2025 to 2007.$y
ends up as the year argument formkTime
(see http://php.net/manual/en/function.mktime.php).that array holds the last date of each calendar month, e.g. January has 31 days.
- To show blog posts from 2007 to 2025.
- The number of days in the month of each month.
However, don't try to learn from the above code!
- Because
blogList($m,$y)
expects values for$y
in the range of 7-25. - Those are the last dates of the months on a Gregorian calendar.
$lastdate holds the number of days in each of the 12 months of the year, and before running the query its trying to find the beginning and ending days of the month.
I'm not sure about the y=25 - that might depend on whats defined in the $query variable
1) Because it's the date from 2007 to 2025. The variable it's set to false because it needs to check something inside blogList, it's counting the days remaining to the end of the month, I think.
2) That's the last day of the month. The array has 12 elements.
精彩评论