How can the floor() function be used to format time differences in PHP?

When calculating time differences in PHP, the floor() function can be used to round down the result to the nearest whole number. This can be useful for formatting time differences in a more readable way, such as converting seconds to minutes or hours. By using floor(), we can ensure that the time difference is displayed in a clean and concise format.

// Calculate time difference in seconds
$time1 = strtotime('2022-01-01 12:00:00');
$time2 = strtotime('2022-01-01 12:30:00');
$timeDiff = $time2 - $time1;

// Convert seconds to minutes using floor()
$minutes = floor($timeDiff / 60);

echo "Time difference: $minutes minutes";