PhpSnip.com

User Stats

Standard Deviation

A simple function designed to calculate the standard deviation of an array of values.

Info

 Download  View Source (print view)
 Rating : 4.7  Views : 471

Source Code ( 17 lines )

function standard_deviation($array) {
	
	//Get sum of array values
	while(list($key,$val) = each($array)) {
		$total += $val;
	}
	
	reset($array);
	$mean = $total/count($array);
	
	while(list($key,$val) = each($array)) {
		$sum += pow(($val-$mean),2);
	}
	$var = sqrt($sum/(count($array)-1));
	
	return $var;
}

Search

Subscribe

  Rss Feeds

Sponsors

Advertise