3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array(9,4,-3,-10); function stddev($array){ //Don Knuth is the $deity of algorithms //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#III._On-line_algorithm $n = 0; $mean = 0; $M2 = 0; foreach($array as $x){ $n++; $delta = $x - $mean; $mean = $mean + $delta/$n; $M2 = $M2 + $delta*($x - $mean); } $variance = $M2/($n - 1); return sqrt($variance); } ?>
Output for 4.3.0 - 7.1.0