// For given month
echo cal_days_in_month(CAL_GREGORIAN, 1, 2021);
// For current month
echo date('t');
cal_days_in_month(CAL_GREGORIAN, $month, $year)
<?php
$months = n; // Here n = …..-2,-1,0,1,2, …..(months to add or subtract)
$years = n; // Here n = …..-2,-1,0,1,2, …..(years to add or subtract)
echo date('Y-m-28', mktime(0, 0, 0, date('m')+$months, 1, date('Y') + $years));
?>
echo cal_days_in_month(CAL_GREGORIAN, 8, 2009);