How can PHP functions like strtotime() be used to calculate date differences in a loop?

When using PHP functions like strtotime() to calculate date differences in a loop, you can store the start date outside the loop and then calculate the difference for each iteration by comparing it with the current date within the loop. This way, you can easily track the date differences without repeatedly converting the dates.

$start_date = strtotime('2022-01-01');
$end_date = strtotime('2022-01-10');

for ($i = 0; $i < 10; $i++) {
    $current_date = strtotime("+{$i} days", $start_date);
    $days_difference = ($current_date - $start_date) / (60 * 60 * 24);
    
    echo "Day {$i}: Date: " . date('Y-m-d', $current_date) . ", Difference: {$days_difference} days\n";
}