这可能真的很简单,但是却引起了我的注意!
我不是编码人员-所以从我所学到的知识中可以看出来-这说得通,除了一个奇怪的问题以外,所有功能都按原样工作。...
我正在填充用于导出到JSON的数组,但是正在添加SQL查询中缺少的所有日期。
除第二个“ WHILE”循环中的datetime变量外,其他所有操作都有效!?!?
循环按预期方式工作-迭代正确的次数并将正确的行添加到数组中。...
while ($nt = $result->fetch_assoc())
{
$temp = array();
$day = new DateTime();
$day->setTimestamp(strtotime($nt['day']));
$day->format('U = d/m/Y');
if ($day < $firstdate) {
$firstdate = $day;
}
// WHILE LOOP INCREMENTS CORRECTLY... so $firstdate is incrementing....
while ($day > $firstdate) {
// THIS LINE DOEsnT SHOW THE INCREMENTED DATE?
$temp[] = array('v' => $firstdate->format('d/m/y'),'f' =>NULL);
$temp[] = array('v' => intval(0),'f' =>NULL);
$rows[] = array('c' => $temp);
$firstdate->add(new DateInterval('P1D'));
}
// THIS LINE DISPLAYS IT CORRECTLY!
$temp[] = array('v' => $firstdate->format('d/m/y'),'f' =>NULL);
$temp[] = array('v' => intval($nt['output']),'f' =>NULL);
$rows[] = array('c' => $temp);
$firstdate->add(new DateInterval('P1D'));
}
我从上面获得的输出类似(实际结果请参见最后的图片!):
我得到的---> 19/10/26 27 ------>正确
我得到的---> 19 27/10/0 ------>正确
我得到的---> 19/10/19 0 ------>期待“ 28/10/19 0”
我得到的---> 19/10/19 0 ------>期待“ 29/10/19 0”
我得到的---> 19/10/30 25 ------>正确
我得到的---> 19/10/31 0 ------>正确
我得到的---> 19/01/11 45 ------>正确
因此“ $ firstdate”正在递增,但是当我将其写到数组中时,它仍然具有旧值吗?但是只有在while循环中吗?!