$days = cal_days_in_month(CAL_GREGORIAN, 4, 2013);
echo "Number of days in April 2013 = $days";
The output is here
Number of days in April 2013 = 30
Syntax is here:
cal_days_in_month(type of calendar, month, year )
Number of days in present month
There is a better way to get the number of days in present month by using date formats. Here is the code
echo date('t');
The output is here
31
Number of days in next month
We can read the present month and present year by using date() function. Then we will 1 to present month to get next month and then get the number of days in that month.
$m= date('m');// Present Month
$y= date('Y'); // Preseent year
$no_of_days = date('t',mktime(0,0,0,$m+1,1,$y));
// This is to calculate number of days in next month
echo " Number of days in Next to $m month :$no_of_days";
The output is here Number of days in Next to 10 month : 30 You can read more on date format here
Number of days in previous month
From the present month we can subtract 1 to get previous month
$no_of_days = date('t',mktime(0,0,0,$m-1,1,$y));
// to calculate number of days in previous month