{* *}
code teams

monthArray



Pass in a length to return month names as a common 1 or 3 character abbreviation, or the full name, plus the days for each month, including february calculated for leap years. Pass in the year if not the current year.

function daysInFebruary($year)
{
    return ((($year % 4 == 0) && ( (!($year % 100 == 0)) || ($year % 400 == 0))) ? 29 : 28 );
}


function monthArray($len = 0, $y = 0)
{
    if ($y == 0) {
        $y = date("Y");
    }
    
    $monthArr = array(
        array("name" => "January", "days" => 31),
        array("name" => "February", "days" => 28),
        array("name" => "March", "days" => 31),
        array("name" => "April", "days" => 30),
        array("name" => "May", "days" => 31),
        array("name" => "June", "days" => 30),
        array("name" => "July", "days" => 31),
        array("name" => "August", "days" => 31),
        array("name" => "September", "days" => 30),
        array("name" => "October", "days" => 31),
        array("name" => "November", "days" => 30),
        array("name" => "December", "days" => 31)
    );
    if ($len != 0) {
        for ($x = 0; $x < count($monthArr); $x++) {
            $monthArr[$x]["name"] = substr($monthArr[$x]['name'], 0, $len);
        }
    }
    
    //get days in february
    $monthArr[1]['days'] = daysInFebruary($y);
    
    return $monthArr;
    
}