2 回答

TA貢獻1806條經驗 獲得超5個贊
這對我有用:
//split into start and end points
array_push($times, $last);
$test = array_chunk($times, 2);
$free_slots = array();
$interval = '+20 minutes';
$end_test = count($times)/2;
//split into 'x' min intervals
for($i=0; $i<$end_test; $i++){
array_push($free_slots, $test[$i][0]);
$mod = clone $test[$i][0];
while($mod < $test[$i][1]){
$m = clone $mod->modify($interval);
array_push($free_slots, $m);
if($m != $test[$i][1]){
array_push($free_slots, $m);
}
}
}

TA貢獻1824條經驗 獲得超6個贊
您$test1每次都需要通過內部循環進行克隆。否則,您只是在適當的位置修改它并推送對相同對象的引用。
但是,在分配$test1and時不需要克隆原始日期$test2。你永遠不會修改$test2,所以它不需要是一個克隆。并且$test1在克隆它之后,您在進入循環之前不會進行修改。
for($i=0;$i<$end_test;$i++){
$test1 = $test[$i][0];
$test2 = $test[$i][1];
while($test1<=$test2){
$test1 = clone $test1;
$test1->modify($interval);
array_push($free_slots, $test1);
}
}
- 2 回答
- 0 關注
- 155 瀏覽
添加回答
舉報