} unset($array[0]); return array_sum($array) / count($array); } //get standard deviation public function standardArray($File) { $avg = $this->avgArray($File); $standard_deviation = 0; for ($i = 1; $i < count($File); $i++) { $standard_deviation = $standard_deviation + ($File[$i][1] - $avg) * ($File[$i][1] - $avg); } return sqrt($standard_deviation / (count($File) - 1)); } } $File = getdata('./test.csv'); function getdata($File) { $handle = fopen($File, 'r'); while (!feof($handle)) { $csv[] = fgetcsv($handle); } fclose($handle); return $csv; } $read = new readCSV(); $max = $read->maxArray($File); $min = $read->minArray($File); $mean = $read->meanArray($File); $avg = $read->avgArray($File); $standard = $read->standardArray($File);
unset($murderNum[0]); try { return array_sum($murderNum) / count($murderNum); } catch (Exception $e) { return $e->getMessage(); } } //get standard deviation public function standardArray() { $csv = $this->File; $avg = $this->meanArray($csv); $standard_deviation = 0; for ($i = 1; $i < count($csv); $i++) { if (isset($csv[$i][2])) { $standard_deviation = $standard_deviation + ($csv[$i][2] - $avg) * ($csv[$i][2] - $avg); } } try { return sqrt($standard_deviation / (count($csv) - 1)); } catch (Exception $e) { return $e->getMessage(); } } } $read = new readCSV('undead.csv'); $max = $read->maxArray(); $min = $read->minArray(); $range = $read->rangeArray(); $mean = $read->meanArray(); $standard = $read->standardArray();