public static function numberOfDaysInMonth($month = 0, $year = 0)
    {
        if ($month < 1 or $month > 12) {
            return 0;
        }

        if (!is_numeric($year) or strlen($year) != 4) {
            $year = date('Y');
        }

        if ($month == 2) {
            if ($year % 400 == 0 or ($year % 4 == 0 and $year % 100 != 0)) {
                return 29;
            }
        }

        $days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        return $days_in_month[$month - 1];
    }
public static function numberOfDaysInMonth($month = 0, $year = 0)
    {
        if ($month < 1 or $month > 12) {
            return 0;
        }

        if (!is_numeric($year) or strlen($year) != 4) {
            $year = date('Y');
        }

        if ($month == 2) {
            if ($year % 400 == 0 or ($year % 4 == 0 and $year % 100 != 0)) {
                return 29;
            }
        }

        $days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        return $days_in_month[$month - 1];
    }
public static function numberOfDaysInMonth ( $ month = 0 , $ year = 0 ) { if ( $ month < 1 or $ month > 12 ) { return 0 ; } if ( ! is_numeric ( $ year ) or strlen ( $ year ) != 4 ) { $ year = date ( 'Y' ) ; } if ( $ month == 2 ) { if ( $ year % 400 == 0 or ( $ year % 4 == 0 and $ year % 100 != 0 ) ) { return 29 ; } } $ days_in_month = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; return $ days_in_month [ $ month - 1 ] ; }
Returns the number of days for the given month and year.

@param int $month Month to check
@param int $year  Year to check

@return int
Returns the number of days for the given month and year .