How can the DateTime::add method be used in PHP to add days to a date?

To add days to a date in PHP using the DateTime::add method, you can create a new DateTime object representing the initial date, then use the add method to add the desired number of days. This method allows you to easily manipulate dates in PHP without having to manually calculate new dates.

$initialDate = new DateTime('2022-01-01');
$daysToAdd = 7;
$initialDate->add(new DateInterval('P' . $daysToAdd . 'D'));
echo $initialDate->format('Y-m-d'); // Output: 2022-01-08