I'm stuck in a PHP function: given a start date (ie. 2011-11-25) and an end date (ie. 2011-03-18), I'd like to get an array containing years > months > dates like this:
Array
(
[2010] => Array
(
[11] => Array
(
[0] => 25
[1] => 26
[2] => 27
[3] => 28
[4] => 29
[5] => 30
)
[12] => Array
(
[0] => 01
[1] => 02
[2] => 03
[3] => 04
[4] => 05
[5] => 06
[6] => 07
[7] => 08
[8] => 09
[9] => 10
[10] => 11
[11] => 12
[12] => 13
[13] => 14
[14] => 15
[15] => 16
[16] => 17
[17] => 18
[18] => 19
[19] => 20
[20] => 21
[21] => 22
[22] => 23
[23] => 24
[24] => 25
[25] => 26
[26] => 27
[27] => 28
[28] => 29
[29] => 30
[30] => 31
)
)
[2011] => Array
(
[01] => Array
(
[0] => 01
[1] => 02
[2] => 03
[3] => 04
[4] => 05
[5] => 06
[6] => 07
[7] => 08
[8] => 09
[9] => 10
[10] => 11
[11] => 12
[12] => 13
[13] => 14
[14] => 15
[15] => 16
[16] => 17
[17] => 18
[18] => 19
[19] => 20
[20] => 21
[21] => 22
[22] => 23
[23] => 24
[24] => 25
[25] => 26
[26] => 27
[27] => 28
[28] => 29
[29] => 30
[30] => 31
)
[02] => Array
(
[0] => 01
[1] => 02
[2] => 03
[3] => 04
[4] => 05
[5] => 06
[6] => 07
[7] => 08
[8] => 09
[9] => 10
[10] => 11
[11] => 12
[12] => 13
[13] => 14
[14] => 15
[15] => 16
[16] => 17
[17] => 18
[18] => 19
[19] => 20
[20] => 21
[21] => 22
[22] => 23
[23] => 24
[24] => 25
[25] => 26
[26] => 27
[27] => 28
)
[03] => Array
(
[0] => 01
[1] => 02
[2] => 03
[3] => 04
[4] => 05
[5] => 06
[6] => 07
[7] => 08
[8] => 09
[9] => 10
[10] => 11
[11] => 12
[12] => 13
[13] => 14
[14] => 15
[15] => 16
[16] => 17
[17] => 18
)
)
)
Googling around I found a function to get an array containing years > months:
function get_months($startstring, $endstring) {
$time1 = strtotime($startstring);
$time2 = strtotime($endstring);
$year1 = date('Y', $time1);
$year2 = date('Y', $time2);
$years = range($year1, $year2);
foreach ($years as $year) {
$months[$year] = array();
while ($time1 < $time2) {
if (date('Y', $time1) == $year){
$month = date('m', $time1);
$months[$year][$month] = array();
$time1 = strtotime(date('Y-m', $time1).' +1 month');
} else {
break;
}
}
}
return $months;
}
// ----------------------------------------------------------------
foreach(array_keys($montharr) as $year){
foreach($montharr[$year] as $month){
print "{$year}-{$month}<br>";
}
}
But I have no idea how implementing days too
Please, any help?