【问题标题】:endless loop with date function带日期功能的无限循环
【发布时间】:2011-03-16 14:18:20
【问题描述】:

我按照试图制作日历的 php 书。问题是,即使我按照字母的代码进行操作,我也会遇到障碍。

这是书中的一个循环

    for ( $i=1, $c=1, $t=date('j'), $m=date('m'), $y=date('Y');
            $c<=$this->_daysInMonth; ++$i )

这适用于我从书籍网站下载的示例,但不适用于我的代码。我不明白这怎么会导致除了无限循环之外的任何事情。

编辑

这是整个功能,现在可以了,但我还是不明白如何......

    $html .= "\n\t<ul>"; // ny liste
    for ( $i=1, $c=1, $t=date('j'), $m=date('m'), $y=date('Y'); $c<=$this->_daysInMonth; ++$i) //endless loop legg til ++$c 
    {

        /*
         * Apply a "fill" class
         */
        $class = $i <= $this->_startDay ? "fill" :NULL; 

        /*
         * Add today to current date
         */
        if ( $c == $t && $m == $this->_m && $y == $this->_y )
        {
            $class = "today"; 
        }

        /*
         * Build opening and closing list for item tags
         */
        $ls = sprintf("\n\t\t<li class=\"%s\">", $class); 
        $le = "\n\t\t</li>"; 

        /*
         * add the day of the month to identify the calender box
         */
        if ( $this->_startDay < $i && $this->_daysInMonth >= $c)
        {
            $date =sprintf("\n\t\t\t<strong>%02d</strong>", $c++); 
        }
        else 
        { 
            $date="&nsbp;";
        }

        /*
         * If the current date is saturday wrap the next row
         */
        $wrap = $i != 0 && $i%7 == 0 ? "\n\t</ul>\n\t<ul>" : NULL;
        $html .= $ls . $date . $le . $wrap; 

    }

【问题讨论】:

标签: php date loops for-loop


【解决方案1】:

$c 在这一行中递增:

$date =sprintf("\n\t\t\t<strong>%02d</strong>", $c++);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-12
    • 2019-03-03
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    相关资源
    最近更新 更多