What PHP function can be used to determine the day of the week and how can it be integrated into a script that requires the calendar week to start on Sunday?

To determine the day of the week in PHP, you can use the `date()` function with the 'w' format character which returns a numeric representation of the day of the week (0 for Sunday, 6 for Saturday). To make the calendar week start on Sunday, you can adjust the output accordingly by adding 1 and taking the modulo 7 of the result.

// Get the day of the week starting from 0 for Sunday
$dayOfWeek = date('w');
// Adjust the day to start from 1 for Sunday
$dayOfWeek = ($dayOfWeek + 1) % 7;