What are common pitfalls when using date('w') in PHP to retrieve the weekday of a specific date?

When using date('w') in PHP to retrieve the weekday of a specific date, a common pitfall is that the function returns the weekday starting from 0 for Sunday to 6 for Saturday. This can lead to confusion if you expect Monday to be 1. To solve this, you can add 1 to the result of date('w') to adjust the weekday numbering.

$date = '2022-01-10'; // Example date
$weekday = (date('w', strtotime($date)) + 1) % 7; // Get the weekday and adjust numbering
echo $weekday; // Output the adjusted weekday