简体   繁体   English

function 我无法理解 php

[英]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, $lastDate[$month - 1], $year);


    $query = .......;
}
  1. i don't know why he set the $y=25 .我不知道他为什么设置$y=25 $showYear = false;
  2. why the $lastDate = array(31,29,31,30,31,30,31,31,30,31,30,31);为什么$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 ). $y = 25是因为他从 2025 年向后循环到 2007 年。 $y最终作为mkTime的年份参数(请参阅http://php.net/manual/en/function.mktime.php )。

  2. that array holds the last date of each calendar month, eg January has 31 days.该数组保存每个日历月的最后日期,例如一月有 31 天。

  1. To show blog posts from 2007 to 2025.显示 2007 年至 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.因为blogList($m,$y)期望$y的值在 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. $lastdate 保存一年中 12 个月中每个月的天数,在运行查询之前,它会尝试查找该月的开始和结束日期。

I'm not sure about the y=25 - that might depend on whats defined in the $query variable我不确定 y=25 - 这可能取决于 $query 变量中定义的内容

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. 1)因为它是从 2007 年到 2025 年的日期。它设置为 false 的变量是因为它需要检查 blogList 中的某些内容,我认为它正在计算到月底的剩余天数。

2) That's the last day of the month. 2) 那是一个月的最后一天。 The array has 12 elements.该数组有 12 个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM