Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
   4  
   5  use PhpOffice\PhpSpreadsheet\Calculation\Functions;
   6  
   7  class Minimum extends MaxMinBase
   8  {
   9      /**
  10       * MIN.
  11       *
  12       * MIN returns the value of the element of the values passed that has the smallest value,
  13       *        with negative numbers considered smaller than positive numbers.
  14       *
  15       * Excel Function:
  16       *        MIN(value1[,value2[, ...]])
  17       *
  18       * @param mixed ...$args Data values
  19       *
  20       * @return float
  21       */
  22      public static function min(...$args)
  23      {
  24          $returnValue = null;
  25  
  26          // Loop through arguments
  27          $aArgs = Functions::flattenArray($args);
  28          foreach ($aArgs as $arg) {
  29              // Is it a numeric value?
  30              if ((is_numeric($arg)) && (!is_string($arg))) {
  31                  if (($returnValue === null) || ($arg < $returnValue)) {
  32                      $returnValue = $arg;
  33                  }
  34              }
  35          }
  36  
  37          if ($returnValue === null) {
  38              return 0;
  39          }
  40  
  41          return $returnValue;
  42      }
  43  
  44      /**
  45       * MINA.
  46       *
  47       * Returns the smallest value in a list of arguments, including numbers, text, and logical values
  48       *
  49       * Excel Function:
  50       *        MINA(value1[,value2[, ...]])
  51       *
  52       * @param mixed ...$args Data values
  53       *
  54       * @return float
  55       */
  56      public static function minA(...$args)
  57      {
  58          $returnValue = null;
  59  
  60          // Loop through arguments
  61          $aArgs = Functions::flattenArray($args);
  62          foreach ($aArgs as $arg) {
  63              // Is it a numeric value?
  64              if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) && ($arg != '')))) {
  65                  $arg = self::datatypeAdjustmentAllowStrings($arg);
  66                  if (($returnValue === null) || ($arg < $returnValue)) {
  67                      $returnValue = $arg;
  68                  }
  69              }
  70          }
  71  
  72          if ($returnValue === null) {
  73              return 0;
  74          }
  75  
  76          return $returnValue;
  77      }
  78  }