I am using this to find the total number of days in a month dynamically
$count = cal_days_in_month(CAL_GREGORIAN, $_POST[\'PayMonth\'], $_POST[\'PayYear\']);
function countDays($year, $month, $ignore) {
$count = 0;
$counter = mktime(0, 0, 0, $month, 1, $year);
while (date("n", $counter) == $month) {
if (in_array(date("w", $counter), $ignore) == false) {
$count++;
}
$counter = strtotime("+1 day", $counter);
}
return $count; }echo countDays(2013, 1, array(0, 6)); // 23
Reference : link1 and link2