I'm calculating daily averages of $spent in a table using mysql. In php, I'd like to average all those daily averages into 1 average daily average. Eventually, I'd like to do this for multiple tables and graph the final averages in highcharts. Right now, I can't get php to average the results of my query. I am connecting to my database, but just not showing it in the code. See code below:
<?php
    function array_average($arr){
        $sum = array_sum($arr);
        $num = sizeof($arr);
        echo $sum/$num;
    }
    $sth = mysql_query("SELECT round((sum(d_power),2) as $perton FROM pheom.pheom_gb WHERE timestamp between subdate(curdate(), interval 3 month) and curdate() GROUP BY Day(timestamp) ORDER BY Timestamp");
    $rows = array();
    while($r = mysql_fetch_array($sth)) {
        $rows['data'][] = $r['$perton'];
    }
    echo array_average($rows);
    mysql_close($con);
?>