List of previous and upcoming months to a given date (year and month)
Be aware that in some scenarios, strtotime() may have a limitation.  Furthermore using property DateTime objects will provide greater utility if you decide to extend functionality in the future.

This task is well-suited for DatePeriod.  It will serve you up a collection of date objects that you can format however you wish.

Code: (Demo)

function rangeOfMonths($prior, $ahead, $baseYear = null, $baseMonth = null) {
    $baseYear = $baseYear ?: date('Y');
    $baseMonth = $baseMonth ?: date('m');

    $rangeStart = new DateTime($baseYear . '-' . $baseMonth . '-01 23:59:59');
    $rangeEnd = clone($rangeStart);

    $rangeStart-&gt;modify("-{$prior} month");
    $rangeEnd-&gt;modify("+{$ahead} month +1 day");

    $period = new DatePeriod($rangeStart, new DateInterval('P1M'), $rangeEnd);
    $monthsList = [];
    foreach ($period as $i =&gt; $dateObject) {
        $monthsList[] = [
            'year'       =&gt; $dateObject-&gt;format('Y'), 
            'nr_month'   =&gt; $dateObject-&gt;format('n'), 
            'month_name' =&gt; $dateObject-&gt;format('M'),
            'current'    =&gt; $i == $prior
        ];     
    }
    return $monthsList;
}

var_export(rangeOfMonths(5, 6));



Instead of bloating the function declaration syntax with an array type argument which has two elements (with potentially falsey / non-date-oriented values), write these optional values as individually served arguments and write them as the final arguments.  This will allow you to call this function without needing to pass the array structure.  If your incoming data is already an indexed array with upto two elements, just ... (splat operator) the array when calling the function.
Either way, using any falsey default values will benefit your script by allowing you to leverage the brief ?: (elvis operator).


+1 day is to make the date range inclusive of the final month.

*Timezone impact was not included in my review, you may want to investigate fringe cases and set the timezone per your application's requirements.