为每个唯一月份创建一个div

Im retrieving an array from a database with a list of entries, like so:

$result = getMySales($_SESSION["userID"]);

Each of these entries have a date column. I convert this array to a two-dimensional array where I group all dates with the same year, like so.

$years = Array();

foreach($result as $d) {
    list($y, , ) = explode("-",$d["dato"]); //the date is on the form YYYY-mm-dd
    $years[$y][] = $d;
}
$years = array_values($years);

Now I want to create a new div for each unique month. Meaning "January 2016" and "January 2017" would have each its own div. Lets say the dates are "2017-01-03", "2017-01-04", "2017-02-01". In this case I would like one div containing {"2017-01-03", "2017-01-04"} and one containing {"2017-02-01"}.

Now, maybe I've gone about this the wrong way. Maybe I should have started with a 3-dimensional array. Hope someone can help. Thank you!