here you go, 🙂 this should shave the code down to a bare min, and only requires 1 template to print the outcome.
the formulas, might be a little complicated at first, but are easy of you break them down. using - / and intval
6 lines max for calculation.
// Credits to Neil Wattam... | IF USED
$inputval = '3661'; // USER DEFINES NUMBER OF SECONDS FOR WORKING OUT | 3661 = 1HOUR 1MIN 1SEC
$unith =3600; // Num of seconds in an Hour...
$unitm =60; // Num of seconds in a min...
$hh = intval($inputval / $unith); // '/' given value by num sec in hour... output = HOURS
$ss_remaining = ($inputval - ($hh * 3600)); // '*' number of hours by seconds, then '-' from given value... output = REMAINING seconds
$mm = intval($ss_remaining / $unitm); // take remaining sec and devide by sec in a min... output = MINS
$ss = ($ss_remaining - ($mm * 60)); // '*' number of mins by seconds, then '-' from remaining sec... output = REMAINING seconds.
echo "ss: " . $ss . "<br>";
echo "mm: " . $mm . "<br>";
echo "hh: " . $hh . "<br>";
let me know what you think