setTime(0, 0, 0); $max = new DateTime($endTime); $max->setTime(23, 59, 59); $curr = clone $min; while ($curr < $max) { $month = $curr->format('Y-m'); if (in_array($month, $monthList)) { if (!isset($res[$month])) { $res[$month] = 0; } $res[$month] ++; } $curr->modify('+1 day'); } return $res; } }