开发者

a function i can't understand in php

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 = .......;
}
  1. i don't know why he set the $y=25.$showYear = false;
  2. why the $lastDate = array(31,29,31,30,31,30,31,31,30,31,30,31);?


  1. $y = 25 is because he's looping backwards from 2025 to 2007. $y ends up as the year argument for mkTime (see http://php.net/manual/en/function.mktime.php).

  2. that array holds the last date of each calendar month, e.g. January has 31 days.


  1. To show blog posts from 2007 to 2025.
  2. The number of days in the month of each month.

However, don't try to learn from the above code!


  1. Because blogList($m,$y) expects values for $y in the range of 7-25.
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜