Our teacher gave us a days in month function in php, 99% of it i understand apart from the final element where he accesses the array. Due to a lack of info on this, could someone explain the last line of executed code to me - because it looks like we access the array according to the variable $month and then read -1 from that which makes bugger all sense to me!:
[/code][/code]function days_in_month($month=0,$year='')
{
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=array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
return $days_in_month[$month - 1];
}
Modifié par TrekSL, 05 août 2011 - 02:44 .