0

我试图找到用户提供的一天,但我收到错误:

致命错误:允许的内存大小为 134217728 字节已用尽(尝试分配 79 字节)

$days = $array('saturday','sunday'); // it's dynamic array

if(sizeof($days)>0) {

  foreach($days as $key => $value) {
    $start  = strtotime("today"); // your start/end dates here
    $end    = strtotime("today +6 years");
    $friday = strtotime(strtolower($value), $start);

    while($friday <= $end) {
      //$daysbox[] = date("Y-m-d", $friday);                
    }
  }

}
4

2 回答 2

1
while($friday <= $end) {
    $daysbox[] = date("Y-m-d", $friday);                
}

Assuming it crashes in that way when that line is not commented out: (Otherwise you would have an infinite loop, but it would not crash with the error you described).

You're not changing $friday, you're not changing $end. This means that if the condition is true once, it will continue to stay true. All you do is add something to an array. If you do this an infinite number of times, sooner or later you will run out of memory.

You probably want to change the $friday variable inside your while-loop, like this:

while($friday <= $end) {
    $friday = strtotime("+1 weeks", $friday);
}
于 2013-09-27T12:24:24.740 回答
1

您的 while 循环中绝对没有任何事情发生。您的代码将遇到该 while 循环,而您将陷入无限循环。

于 2013-09-27T12:23:05.530 回答