% is modulo, it the rest of the division
A / B = C, rest=D
A % B = D
"$s = $s % $d" is the same like "$s %= $d"
$hours = floor($sec / 3600);
if ($hours < 10) $hours = "0" . $hours;
$sec %= 3600;
$min = floor($sec / 60);
if ($min < 10) $min = "0" . $min;
$sec %= 60;
if ($sec < 10) $sec = "0" . $sec;
not quite sure if that works, but it should 🙂