数组月报,但不是从1月1日开始

I have a large array of booking dates and amount, like so :

Array
(
[0] => Array
    (
        [date] => 2014-04-04
        [total] => 30.00
    )

[1] => Array  
    (
        [date] => 2014-04-05 
        [total] => 47.00
    )

[9998] => Array
    (
        [date] => 2014-08-21
        [total] => 52.00
    ) 
    ... ++ a lot of dates associated to numbers.   

and process it to get monthly reports :

$months = array();
foreach($myarray as $k=>$v) {
    list($y,$m) = explode("-",$v['date']);
    $months[$y."-".$m][] = $v['total'];
}

which gives me a nice array :

Array
(
    [2014-04] => Array    <-- Every amount made in April
        (
            [0] => 30.00
            [1] => 47.00
            [2] => 47.00
            ...
        )

    [2014-05] => Array     <-- Every amount made in May
        (
            [0] => 68.00
            [1] => 42.00
            ....
        )...

However I'm trying to find a way the same thing but starting from a specific day, say 5 for example, in order to get (dates labelled for clarity):

Array
(
    [from January 5 to February 4] => Array
        (
            [0] => 30.00
            [1] => 47.00
            [2] => 47.00
        )

    [from February 5 to March 4] => Array
        (
            [0] => 30.00
            [1] => 47.00
            [2] => 47.00
        )...

So every amount made each month, but starting from the 5th of each month.

Something like this should work. I hate saying should, but I don't have the data to test with. Let me know if anything's wrong:

$months = array();

foreach($months as $k => $v) {
    list($y, $m, $d) = explode("-", $v['date']);

    if($d < 5) {
        if($m == 1) {
            $y--;
            $m = 12;
        } else {
            $m--;
        }
    }

    $months[$y . "-" . $m][] = $v['total'];
}