christo16 Posted March 8, 2007 Share Posted March 8, 2007 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 More sharing options...
kenrbnsn Posted March 8, 2007 Share Posted March 8, 2007 You're creating a two-dimensioned array, where you only want a normal array. Change this: <?php $tat_array[] = array($tat); ?> to <?php $tat_array[] = $tat; ?> Ken Link to comment https://forums.phpfreaks.com/topic/41734-take-average-of-array/#findComment-202345 Share on other sites More sharing options...
christo16 Posted March 8, 2007 Author Share Posted March 8, 2007 Thank you!! Link to comment https://forums.phpfreaks.com/topic/41734-take-average-of-array/#findComment-202651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.