3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getHours($time) { return $time / 3600; } function getMinutes($time) { return $time / 60 % 60; } function getSeconds($time) { return $time % 60; } function statAssoc($strg) { $return = 'Range: %02d|%02d|%02d Average: %02d|%02d|%02d Median: %02d|%02d|%02d'; $results = array_map(function($result) { return explode('|', trim($result)); }, explode(',', $strg)); $sums = []; for ($i = 0; $i < count($results); $i++) { $sums[] = ($results[$i][0] * 60 * 60) + ($results[$i][1] * 60) + ($results[$i][2]); } $range = max($sums) - min($sums); $average = array_sum($sums) / count($results); $median = (count($results) % 2 !== 0) ? $sums[floor(count($sums) / 2)] + $sums[ceil(count($sums) / 2)] : $sums[ceil(count($sums) / 2)]; var_dump(count($results) % 2); return sprintf( $return, getHours($range), getMinutes($range), getSeconds($range), getHours($average), getMinutes($average), getSeconds($average), getHours($median), getMinutes($median), getSeconds($median) ); } echo statAssoc("01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17, 1|1|1");
based on 6jmoh
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0rc3
int(0) Range: 01|16|16 Average: 01|31|54 Median: 01|32|34