在两个日期范围之间划分周


Split weeks between two date range

从两个日期范围逐周拆分。

例如:

起始日期:2015-01-11

结束日期:2015-01-31

需要这种格式:

第1周:

Array ( [0] => 2015-01-11 [1] => 2015-01-12 [2] => 2015-01-13 [3] => 15-01-14 [4] => 2015-01-15 [5] => 2015-01-16 [6] => 2015-01-17 

第2周:

Array([0] => 2015-01-18 [1] => 2015-01-19 [2] => 2015-01-20 [3] => 2015-01-21 [4] => 2015-01-22 [5] => 2015-01-23 [6] => 2015-01-24)

第3周:

Array([0] => 2015-01-25 [1] => 2015-01-26 [2] => 2015-01-27 [3] => 2015-01-28 [4] => 2015-01-29 [5] => 2015-01-30 [6] => 2015-01-31)

感谢提前。

这样的东西对你有用吗?

<?php
 // Set timezone
 date_default_timezone_set('UTC');
 // Start date
 $date = '2015-01-11';
 // End date
 $end_date = '2015-01-31';
 $array_final = array();
 $array  = array();
 $i=0;
 while (strtotime($date) <= strtotime($end_date)) {
     if($i%6==0 && $i>0){
         array_push($array_final,$array);   
         $array  = array();
     }
    array_push($array,$date);    
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
    $i++;
}
print_r($array_final);
?>

它为每个星期返回一个带有一行的数组。每个弱行都返回您想要的内容:一个从0到6的数组,其中包含日期

你可以在phpFiddle 上试试

阵列(

[0]=>阵列([0]=>2015-01-11[1]=>2015-01-12[2]=>2015-01-13[3]=>2015-01-14[4]=>2015-01-15[5]=>2015-01-16)

[1] =>阵列([0]=>2015-01-17[1]=>2015-01-18[2]=>2015-01-19[3]=>2015-01-20[4]=>2015-01-21[5]=>2015-01-22)

[2] =>阵列([0]=>2015-01-23[1]=>2015-01-24[2]=>2015-01-25[3]=>2015-01-26[4]=>2015-01-27[5]=>2015-01-28)