You are here

private static function PHPExcel_Calculation_Statistical::_modeCalc in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php \PHPExcel_Calculation_Statistical::_modeCalc()
1 call to PHPExcel_Calculation_Statistical::_modeCalc()
PHPExcel_Calculation_Statistical::MODE in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php
* MODE * * Returns the most frequently occurring, or repetitive, value in an array or range of data * * Excel Function: * MODE(value1[,value2[, ...]]) * * @access public * @category Statistical Functions *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php, line 2399

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

private static function _modeCalc($data) {
  $frequencyArray = array();
  foreach ($data as $datum) {
    $found = False;
    foreach ($frequencyArray as $key => $value) {
      if ((string) $value['value'] == (string) $datum) {
        ++$frequencyArray[$key]['frequency'];
        $found = True;
        break;
      }
    }
    if (!$found) {
      $frequencyArray[] = array(
        'value' => $datum,
        'frequency' => 1,
      );
    }
  }
  foreach ($frequencyArray as $key => $value) {
    $frequencyList[$key] = $value['frequency'];
    $valueList[$key] = $value['value'];
  }
  array_multisort($frequencyList, SORT_DESC, $valueList, SORT_ASC, SORT_NUMERIC, $frequencyArray);
  if ($frequencyArray[0]['frequency'] == 1) {
    return PHPExcel_Calculation_Functions::NA();
  }
  return $frequencyArray[0]['value'];
}