How can PHP be used to calculate the number of days between two dates?

To calculate the number of days between two dates in PHP, you can use the `DateTime` class to create objects representing the two dates. Then, you can calculate the difference between the two dates using the `diff` method and access the `days` property of the resulting `DateInterval` object.

$date1 = new DateTime('2022-01-01');
$date2 = new DateTime('2022-01-10');

$interval = $date1->diff($date2);
echo $interval->days; // Output: 9