echo standardDeviation([5, 9, 4, 3, 2])."\n";

// Calculates standard deviation for the given integer array
function standardDeviation($a){
	$count=count($a);
	$v=0;
	
	// Calculates average number from the array
    $avg = array_sum($a) / $count;
    
    // Loops through the array members
    foreach ($a as $i){
    	// Calculates the sum of squares of the difference 
    	// between each member and the average of the array
    	$v+=pow(($v-$avg), 2);
    }
    return sqrt($v/$count);
}
by ვაჟა ტყემალაძე
2 years ago
PHP
Problem Solving
php
Note
Problem
PHP Object Oriented Programming (OOP)
0
Pro tip: use ```triple backticks around text``` to write in code fences