3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function secondsToString($seconds) { $units = ['day' => 86400, 'hour' => 3600, 'minute' => 60, 'second' => 1]; $parts = []; foreach ($units as $name => $duration) { $div = floor($seconds / $duration); if ($div == 0) { continue; } $parts[] = $div == 1 ? "{$div} {$name}" : "{$div} {$name}s"; $seconds %= $duration; } $last = array_pop($parts); return empty($parts) ? $last : join(', ', $parts) . " and " . $last; } echo secondsToString(245);
based on NUiPK
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0rc3
4 minutes and 5 seconds