lib/Math/Statistics.php
public static function variance(array $values, $sample = false)
    {
        $average = self::mean($values);
        $sum = 0;

        foreach ($values as $value) {
            $diff = pow($value - $average, 2);
            $sum += $diff;
        }

        if (count($values) === 0) {
            return 0;
        }

        $variance = $sum / (count($values) - ($sample ? 1 : 0));

        return $variance;
    }
public static function variance(array $values, $sample = false)
    {
        $average = self::mean($values);
        $sum = 0;

        foreach ($values as $value) {
            $diff = pow($value - $average, 2);
            $sum += $diff;
        }

        if (count($values) === 0) {
            return 0;
        }

        $variance = $sum / (count($values) - ($sample ? 1 : 0));

        return $variance;
    }
public static function variance ( array $ values , $ sample = false ) { $ average = self :: mean ( $ values ) ; $ sum = 0 ; foreach ( $ values as $ value ) { $ diff = pow ( $ value - $ average , 2 ) ; $ sum += $ diff ; } if ( count ( $ values ) === 0 ) { return 0 ; } $ variance = $ sum / ( count ( $ values ) - ( $ sample ? 1 : 0 ) ) ; return $ variance ; }
Return the variance for a given population.

@param array $values
@param bool $sample

@return float
Return the variance for a given population .