title: Calculating average value for array with PHP?
body: <p>My head is exploding with this. I can't seem to create a working solution.</p>
  
  <p>I have a file in this format: </p>
  
  <pre><code>99895|35378|0.01
  99895|813|-0.97
  99895|771|0.29
  442|833|-1.06
  442|485|-0.61
  442|367|-0.14
  442|478|0.77
  442|947|-0.07
  7977|987|0.76
  7977|819|0.37
  7977|819|0.36
  7977|653|1.16
  7977|1653|1.15
  </code></pre>
  
  <p>I want to calculate average values from third column for each id from the first column.</p>
  
  <p>This seems so easy but I can't get this to work. How do you get averages for any said id from first column?</p>
  
  <p>EDIT:</p>
  
  <p>Some sample code I've written before:</p>
  
  <pre><code>$file = file_get_contents("results.txt");
  
  
  $file = explode("
  ", $file);
  
  $howMany = count($file);
  
  for($a = 0;$a&lt;$howMany;$a++)
  {
  
  $row = explode("|", $file[$a]);
  $id = $row[0];
  
  
  
  $howManyAlready = count($bigTable[$id]);
  
  $bigTable[$id][$howManyAlready] = $row[2];
  
  }
  </code></pre>
  
  <p>I've added the code. So far it gets the results into an array ( with offset corresponding to its id ) But I am having trouble with how to get those results and calculate average for each id and then present it on the screen.</p>