How can variables be used effectively in date calculations in PHP?

When working with date calculations in PHP, variables can be used effectively to store and manipulate dates. By assigning dates to variables, you can easily perform operations such as adding or subtracting days, months, or years. This can make your code more readable and maintainable.

// Using variables for date calculations in PHP
$date = '2022-01-15';
$days_to_add = 7;
$new_date = date('Y-m-d', strtotime($date . ' + ' . $days_to_add . ' days'));

echo $new_date; // Output: 2022-01-22