Jump to content

Take average of array


christo16

Recommended Posts

Hello all, I am trying to take an average of the difference of two different numbers in a mysql row.  What I did is output them into an array but when I do sum_array(array) it out puts to zero.  Any ideas where I went wrong?

 

$result = mysql_query('SELECT * FROM requests WHERE reqtime >= "'.$date.'" AND status = "ready" OR status = "pu"');
while ($row = mysql_fetch_array($result)) {
//Converts to unix time
$reqstamp = strtotime($row[1]);
$rfpstamp = strtotime($row[61]);
//Finds amt of time between begin and end
$difference = $rfpstamp - $reqstamp;
$tat = $difference /60/60/24; //Converts seconds to days
$tat= round($tat, 3); //Rounds to 2 decimal places

print "Total Turn Around Time: ".$tat."<br>";

print "<br><br>";
//adds the turn around time to the array
$tat_array[] = array($tat);
}

print array_sum($tat_array);

Link to comment
https://forums.phpfreaks.com/topic/41734-take-average-of-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.