How can PHP convert seconds into a format of days:hours:minutes:seconds?

To convert seconds into a format of days:hours:minutes:seconds in PHP, you can use simple arithmetic operations to calculate the number of days, hours, minutes, and seconds from the total number of seconds. You can then format these values into a string in the desired format.

function convertSecondsToDHMS($seconds) {
    $days = floor($seconds / (60 * 60 * 24));
    $hours = floor(($seconds % (60 * 60 * 24)) / (60 * 60));
    $minutes = floor(($seconds % (60 * 60)) / 60);
    $seconds = $seconds % 60;

    return "$days:$hours:$minutes:$seconds";
}

$seconds = 100000;
echo convertSecondsToDHMS($seconds); // Output: 1:3:46:40