日期在PHP中的2个日期没有正确显示

Below code doesn't show the output of the month of 05 as input but if the date range is big then it shows the correct info.

//Code for finding All the Dates between TWO Date
//Code for finding month between two Date
$startDate = new DateTime("2018-04-26");
$inputEndDate = new DateTime("2018-05-03");
$inputEndDate->modify('+1day');//for increasing the day by 1

//for counting the month
$monthInterval = new DateInterval('P1M');
$monthPeriod   = new DatePeriod($startDate, $monthInterval, $inputEndDate);
$monthCount = 0;

foreach ($monthPeriod as $date) {
$endDate = new DateTime(date("Y-m-t", strtotime($date->format('Y-m-d')))); 

//last day of the month

$endDate->modify('+1 day');//for increasing the day by 1
if ($inputEndDate < $endDate) {
    $endDate = $inputEndDate;
}


//var_dump($endDate);

$dateRange = new DatePeriod($startDate, new DateInterval('P1D'), $endDate);
$startDate = $endDate->add(new DateInterval('P1D'))->modify('-1 day');


echo "{$date->format('F')}-{$date->format('Y')}";
foreach($dateRange as $dateHeader){
    echo $dateHeader->format("Y-m-d");
}
$monthCount++;}

Output:

April-2018
2018-04-26
2018-04-27
2018-04-28
2018-04-29
2018-04-30

The output does not show the result of another month as in input.

function get_dates_through_range($start, $end, $format = 'Y-m-d')
{
    $range = array();
    $interval = new DateInterval('P1D');

    $range_end = new DateTime($end);
    $range_end->add($interval);

    $period = new DatePeriod(new DateTime($start), $interval, $range_end);

    foreach($period as $date) {
        $range[] = $date->format($format);
    }

    return $range;
 }

get_dates_through_range('2018-04-30','2018-05-03')

Outputs

array(4) {
    [0]=>
    string(10) "2018-04-30"
    [1]=>
    string(10) "2018-05-01"
    [2]=>
    string(10) "2018-05-02"
    [3]=>
    string(10) "2018-05-03"
 }