How does the "o" format character in the PHP date function help in determining the correct calendar week for a given date?

The "o" format character in the PHP date function returns the ISO-8601 year number of a given date. This is important for determining the correct calendar week because the ISO-8601 week date system is used in many countries and ensures that each week belongs to only one year. By using the "o" format character, you can accurately determine the calendar week for a given date based on the ISO-8601 standard.

$date = "2023-12-31";
$year = date("o", strtotime($date));
$week = date("W", strtotime($date));
echo "The calendar week for $date in ISO-8601 year $year is $week.";