fork download
<html> 
<head></head> 
<body> 
<?php 
class Average{ 
    var $samples; //配列

    function Average(){ 
      $this->samples = array(); 
    }

    //追加 
    function add($value){ 
      $this->samples[sizeof($this->samples)] = $value; 
    }

    //配列件数表示 
    function countValues(){ 
      return sizeof($this->samples); 
    }

    //最大値 
    function getMax(){ 
      $max = 0; 
      foreach ($this->samples as $value) { 
        if ($max < $value) { 
          $max = $value; 
        } 
      } 
      return $max; 
    }

    //平均値 
    function getAverage(){ 
     if(0 == sizeof($this->samples)){ 
        return 0; 
      } 
      $sum = 0; 
      foreach ($this->samples as $value) { 
        $sum += $value; 
      } 
      return $sum / sizeof($this->samples); 
    } 
} 
$avg = new Average; 
for ($i=1; $i <=10 ; $i++) { 
  $avg->add($i); 
} 
echo $avg->getAverage(); 
?>

</body> 
</html>
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
<html> 
<head></head> 
<body> 
5.5
</body> 
</html>