Array
(
[0] => 2018-07-01
[1] => 2018-07-02
[2] => 2018-08-10
[3] => 2018-08-15
[4] => 2018-08-21
[5] => 2019-01-02
[6] => 2019-01-03
[7] => 2019-11-04
)
newdate = {
2018:{
7:[1, 2],
8:[10,15,21]
},
2019:{
1:[2,3],
11:[4]
}
};
$grouped = [];
foreach ($date as $d) {
$parts = explode('-', $d);
$grouped[$parts[0]][intval($parts[1])][] = intval($parts[2]);
}