Get the last month with posts using a recursive function…

Just need to add returnbefore the function.

function last_post( $month,$year ) {
    $args  = array( 'monthnum' => $month, 'year' => $year );
    $query = new WP_Query( $args );
    var_dump( $month ); // int 11, int 10

    if( $query->have_posts() ){
       return $args;
    } else {
       return last_post( $month-1, $year ); // here is the fix!
    }
}

$args = last_post( 11, $year ); // null but ok with 10