Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
   4  
   5  use PhpOffice\PhpSpreadsheet\Calculation\Functions;
   6  
   7  class Counts extends AggregateBase
   8  {
   9      /**
  10       * COUNT.
  11       *
  12       * Counts the number of cells that contain numbers within the list of arguments
  13       *
  14       * Excel Function:
  15       *        COUNT(value1[,value2[, ...]])
  16       *
  17       * @param mixed ...$args Data values
  18       *
  19       * @return int
  20       */
  21      public static function COUNT(...$args)
  22      {
  23          $returnValue = 0;
  24  
  25          // Loop through arguments
  26          $aArgs = Functions::flattenArrayIndexed($args);
  27          foreach ($aArgs as $k => $arg) {
  28              $arg = self::testAcceptedBoolean($arg, $k);
  29              // Is it a numeric value?
  30              // Strings containing numeric values are only counted if they are string literals (not cell values)
  31              //    and then only in MS Excel and in Open Office, not in Gnumeric
  32              if (self::isAcceptedCountable($arg, $k)) {
  33                  ++$returnValue;
  34              }
  35          }
  36  
  37          return $returnValue;
  38      }
  39  
  40      /**
  41       * COUNTA.
  42       *
  43       * Counts the number of cells that are not empty within the list of arguments
  44       *
  45       * Excel Function:
  46       *        COUNTA(value1[,value2[, ...]])
  47       *
  48       * @param mixed ...$args Data values
  49       *
  50       * @return int
  51       */
  52      public static function COUNTA(...$args)
  53      {
  54          $returnValue = 0;
  55  
  56          // Loop through arguments
  57          $aArgs = Functions::flattenArrayIndexed($args);
  58          foreach ($aArgs as $k => $arg) {
  59              // Nulls are counted if literals, but not if cell values
  60              if ($arg !== null || (!Functions::isCellValue($k))) {
  61                  ++$returnValue;
  62              }
  63          }
  64  
  65          return $returnValue;
  66      }
  67  
  68      /**
  69       * COUNTBLANK.
  70       *
  71       * Counts the number of empty cells within the list of arguments
  72       *
  73       * Excel Function:
  74       *        COUNTBLANK(value1[,value2[, ...]])
  75       *
  76       * @param mixed ...$args Data values
  77       *
  78       * @return int
  79       */
  80      public static function COUNTBLANK(...$args)
  81      {
  82          $returnValue = 0;
  83  
  84          // Loop through arguments
  85          $aArgs = Functions::flattenArray($args);
  86          foreach ($aArgs as $arg) {
  87              // Is it a blank cell?
  88              if (($arg === null) || ((is_string($arg)) && ($arg == ''))) {
  89                  ++$returnValue;
  90              }
  91          }
  92  
  93          return $returnValue;
  94      }
  95  }