Getting data, mathing, echo-ing

Hello.

I have some “finish” time in ms. (for example 14000 [14s]). Also I have others guy time like 16789ms. I have made function to math difference between times.

[code]function format_time($t) // t = miliseconds
{
$t1 = 16789;
$t2 = 14000;

$t = $t1 - $t2;
$minutes = floor($t / 60000);
$seconds = sprintf(’%02d’,floor(($t / 1000) % 60));
$ms = sprintf(’%03d’, $t % 1000);
return $minutes . “:” . $seconds . “.” . $ms;
}

echo "+ ";
echo format_time($t);
[/code]

So it will be “+ 0:02.789”

I still have a problem yet. I need to make this script mathing more than 1 time. I need around 20 other times to be mathed with 1st finish time and the difference to be displayed. And that’s my problem.

Can you give me examples or clues how can I give this script values in ms? Then, it should math every value and echo it somewhere. Can you help me in it, please?

Hiya,

Are you wanting to compare the one time $t1 = 16789; with the other 20?
Or find comparisons between all times?

This compares the one time with others.
[php]$t = NULL;
function format_time($t) // t = miliseconds
{
$i = 1;
$array = array(16789,14000,19200,14000,13000,14000,16000);
$len = count($array);

for ($i=1; $i< $len; $i++) {
	$t = $array[0] - $array[$i];
	$minutes = floor($t / 60000);
	$seconds = sprintf('%02d',floor(($t / 1000) % 60));
	$ms = sprintf('%03d', $t % 1000);
	
		if($t > 0){
			echo '+';
		}

	echo $minutes . ":" . $seconds . "." . $ms . "<br \> ";
}

return true;
}

format_time($t);[/php]

Easiest way would be to load it into the array dynamically.
I get
+0:02.789
-1:-2.-411
+0:02.789
+0:03.789
+0:02.789
+0:00.789

Also that negative time seems weird… might be the way you have it calculating or something, I dunno but hope this helps you it some way

Sponsor our Newsletter | Privacy Policy | Terms of Service