This code won't give you exactly what you asked for (data stored in variable variables), but will put the data into an array indexed by yyyymm.
function days_between_by_month($ts_1, $ts_2)
{
$arr[date('Ym', $ts_1)] = date('t', $ts_1) - date('j', $ts_1);
$temp_ts = strtotime(date('m', $ts_1) . '/15/' . date('Y', $ts_1));
while (($temp_ts = strtotime('+1 month', $temp_ts)) < $ts_2) {
$arr[date('Ym', $temp_ts)] = date('t', $temp_ts);
}
$arr[date('Ym', $ts_2)] = date('j', $ts_2);
return $arr;
}
$date_1 = '10/24/2009';
$date_2 = '04/10/2010';
$month_arr = days_between_by_month(strtotime($date_1), strtotime($date_2));
print_r($month_arr);
Array
(
[200910] => 7
[200911] => 30
[200912] => 31
[201001] => 31
[201002] => 28
[201003] => 31
[201004] => 10
)
By setting the interim day of month to the 15th it avoids such problems as adding one month to a late January date and getting a date in March. Also, using the year in the array keys avoids the problem of duplicate keys if the time between date1 and date2 is one year or more.