weeks, days, hours, minutes, seconds <- 2 digit with leading zero!
Just pass the function a var with 'seconds'! The interesting thing is that it uses a loop with a single line of code to build the output array! Much different than using if and else!
Code: Select all
<?
function tick_count ( $s )
{
$out = array ();
( int ) $time = array ( 'years' => 31536000, 'weeks' => 604800, 'days' => 86400, 'hours' => 3600, 'minutes' => 60, 'seconds' => 1 );
foreach ( $time as $n => $v )
{
$s = ( $out[$n] = $s >= $v ? ( $n == 'years' ? floor ( $s / $v ) : sprintf ( "%02d", floor ( $s / $v ) ) ) : 0 ) > 0 ? $s % $v : $s;
}
return ( $out );
}
$new = tick_count ( '37262521' );
print_r($new);
?>printf