PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function race($v1, $v2, $g) { if ($v1 >= $v2) { return null; } else { // s = v * t; // $difSpeed = $v2 - $v1; // per hour //return floor($g / $difSpeed) * 3600; $dec = $g / $difSpeed; // start by converting to seconds $seconds = ($dec * 3600); // we're given hours, so let's get those the easy way $hours = floor($dec); // since we've "calculated" hours, let's remove them from the seconds variable $seconds -= $hours * 3600; // calculate minutes left $minutes = floor($seconds / 60); // remove those from seconds as well $seconds -= $minutes * 60; return [intval($hours), intval($minutes), intval($seconds)]; } }
Show:  
Copy Clear