Php 带日期函数的无限循环
我跟随一本php书籍尝试制作日历。问题是,即使我按照代码进行操作,也会遇到障碍 这是书中的一个循环Php 带日期函数的无限循环,php,date,loops,for-loop,Php,Date,Loops,For Loop,我跟随一本php书籍尝试制作日历。问题是,即使我按照代码进行操作,也会遇到障碍 这是书中的一个循环 for ( $i=1, $c=1, $t=date('j'), $m=date('m'), $y=date('Y'); $c<=$this->_daysInMonth; ++$i ) for($i=1,$c=1,$t=date('j'),$m=date('m'),$y=date('y'); $c_daysInMonth;++$i) 这在我从图书网站下
for ( $i=1, $c=1, $t=date('j'), $m=date('m'), $y=date('Y');
$c<=$this->_daysInMonth; ++$i )
for($i=1,$c=1,$t=date('j'),$m=date('m'),$y=date('y');
$c_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;
}
$html.=“\n\t”;//纽约李斯特
对于($i=1,$c=1,$t=date('j'),$m=date('m'),$y=date('y');$c_daysInMonth;++$i)//
{
/*
*应用“填充”类
*/
$class=$i_startDay?“填充”:空;
/*
*将今天添加到当前日期
*/
如果($c==$t&&$m==$this->\u m&&$y==$this->\u y)
{
$class=“今天”;
}
/*
*为项目标记生成开始和结束列表
*/
$ls=sprintf(“\n\t\t- ,$class);
$le=“\n\t\t
”;
/*
*添加月份的日期以标识日历框
*/
如果($this->u startDay<$i&$this->\u daysInMonth>=$c)
{
$date=sprintf(“\n\t\t\t%02d”,$c++);
}
其他的
{
$date=“&nsbp;”;
}
/*
*如果当前日期为星期六,请换行下一行
*/
$wrap=$i!=0&$i%7==0?\n\t
\n\t“:NULL;
$html.=$ls.$date.$le.$wrap;
}
$c在此行中递增:
$date =sprintf("\n\t\t\t<strong>%02d</strong>", $c++);
$date=sprintf(“\n\t\t\t%02d”,$c++);
变量$c
是否在任何地方递增?那么$this->\u daysInMonth
的值是多少?简单地增加一毫秒计数,然后从简单的日历示例中导出该日期可能更容易