Example #1
0
 /**
  *	VARPA
  *
  *	Calculates variance based on the entire population, including numbers, text, and logical values
  *
  *	Excel Function:
  *		VARPA(value1[,value2[, ...]])
  *
  *	@access	public
  *	@category Statistical Functions
  *	@param	mixed		$arg,...		Data values
  *	@return	float
  */
 public static function VARPA()
 {
     // Return value
     $returnValue = PHPExcel_Calculation_Functions::DIV0();
     $summerA = $summerB = 0;
     // Loop through arguments
     $aArgs = PHPExcel_Calculation_Functions::flattenArrayIndexed(func_get_args());
     $aCount = 0;
     foreach ($aArgs as $k => $arg) {
         if (is_string($arg) && PHPExcel_Calculation_Functions::isValue($k)) {
             return PHPExcel_Calculation_Functions::VALUE();
         } elseif (is_string($arg) && !PHPExcel_Calculation_Functions::isMatrixValue($k)) {
         } else {
             // Is it a numeric value?
             if (is_numeric($arg) || is_bool($arg) || is_string($arg) & $arg != '') {
                 if (is_bool($arg)) {
                     $arg = (int) $arg;
                 } elseif (is_string($arg)) {
                     $arg = 0;
                 }
                 $summerA += $arg * $arg;
                 $summerB += $arg;
                 ++$aCount;
             }
         }
     }
     // Return
     if ($aCount > 0) {
         $summerA *= $aCount;
         $summerB *= $summerB;
         $returnValue = ($summerA - $summerB) / ($aCount * $aCount);
     }
     return $returnValue;
 }