PHP在日期之间循环会导致错误

PHP在日期之间循环会导致错误,php,date,loops,Php,Date,Loops,有谁能告诉我,当日期>=2013-01-06时,为什么以下操作失败 这太奇怪了,当日期在这个日期之后时,脚本工作得非常完美,但在之前,我得到了死亡的白色屏幕 <?php use Carbon\Carbon; $startDate = Carbon::createFromFormat('Y-m-d', '2013-01-06'); $current_week = Carbon::now()->timestamp; /* $startDate = strtotime(

有谁能告诉我,当日期>=2013-01-06时,为什么以下操作失败

这太奇怪了,当日期在这个日期之后时,脚本工作得非常完美,但在之前,我得到了死亡的白色屏幕

<?php 

use Carbon\Carbon;

$startDate    = Carbon::createFromFormat('Y-m-d', '2013-01-06');
$current_week = Carbon::now()->timestamp;

/*
$startDate    = strtotime('2013-01-06');
$current_week = strtotime(date('Y-m-d'));
*/

$weeks        = array();
$w            = 0;

while($startDate < $current_week){
    $weeks[$w] = array(
        'monday' => $startDate->startofWeek()->format('d/m/Y'), 
        'sunday' => $startDate->endofWeek()->format('d/m/Y')
    );
    $w++;
    $startDate = $startDate->addDays(1); // Move it on to the following week
}

var_dump($weeks);

?>


谁能帮帮我

这个?我们比较timestamp和timestamp,而不是带有timestamp的datetime对象,我不知道Carbon类,这里$startDate->timestamp必须由将Carbon datetime对象转换为unix timestamp的方法替换

<?php 

use Carbon\Carbon;

$startDate    = Carbon::createFromFormat('Y-m-d', '2013-01-06');
$startDateTimestamp = $startDate->timestamp;
$current_week = Carbon::now()->timestamp;

/*
$startDate    = strtotime('2013-01-06');
$current_week = strtotime(date('Y-m-d'));
*/

$weeks        = array();
$w            = 0;

while($startDateTimestamp < $current_week){
    $weeks[$w] = array(
        'monday' => $startDate->startofWeek()->format('d/m/Y'), 
        'sunday' => $startDate->endofWeek()->format('d/m/Y')
    );
    $w++;
    $startDate = $startDate->addDays(7); // Move it on to the following week
    $startDateTimestamp = $startDate->timestamp;
}

var_dump($weeks);

?>


服务器的错误日志中出现了什么?您能在某个地方在线发布演示吗?您不应该在开始日期的基础上再增加7天,以移至下一周(而不是1天)吗?由于不了解更多关于碳的信息,我不得不猜测您的问题是碳的一个bug。@MikeW我收到了这个错误[27-Oct-2013 14:14:59 UTC]PHP致命错误:允许的内存大小为33554432字节(尝试分配79字节)在第14行的/Applications/MAMP/htdocs/date/app/views/hello.php中,您正在执行一个无限循环……我发现发生了完全相同的错误。请回显$current\u week,在无限while循环中,如果它增加,回显$startDateTimestamp。您将停留在while循环中。