What are some best practices for calculating the number of days in a month using PHP?

When calculating the number of days in a month using PHP, it's important to consider leap years and varying month lengths. One common approach is to use the `cal_days_in_month()` function provided by PHP, which takes into account leap years. Another approach is to manually calculate the number of days based on the month and year provided.

// Using cal_days_in_month() function
$month = 2; // February
$year = 2022;
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
echo "Number of days in month: " . $daysInMonth;

// Manually calculating the number of days
$month = 2; // February
$year = 2022;
$daysInMonth = date('t', mktime(0, 0, 0, $month, 1, $year));
echo "Number of days in month: " . $daysInMonth;