ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Size.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 class Size
8 {
22  public static function large(...$args)
23  {
24  $aArgs = Functions::flattenArray($args);
25  $entry = array_pop($aArgs);
26 
27  if ((is_numeric($entry)) && (!is_string($entry))) {
28  $entry = (int) floor($entry);
29 
30  $mArgs = self::filter($aArgs);
31  $count = Counts::COUNT($mArgs);
32  --$entry;
33  if (($entry < 0) || ($entry >= $count) || ($count == 0)) {
34  return Functions::NAN();
35  }
36  rsort($mArgs);
37 
38  return $mArgs[$entry];
39  }
40 
41  return Functions::VALUE();
42  }
43 
57  public static function small(...$args)
58  {
59  $aArgs = Functions::flattenArray($args);
60 
61  $entry = array_pop($aArgs);
62 
63  if ((is_numeric($entry)) && (!is_string($entry))) {
64  $entry = (int) floor($entry);
65 
66  $mArgs = self::filter($aArgs);
67  $count = Counts::COUNT($mArgs);
68  --$entry;
69  if (($entry < 0) || ($entry >= $count) || ($count == 0)) {
70  return Functions::NAN();
71  }
72  sort($mArgs);
73 
74  return $mArgs[$entry];
75  }
76 
77  return Functions::VALUE();
78  }
79 
83  protected static function filter(array $args): array
84  {
85  $mArgs = [];
86 
87  foreach ($args as $arg) {
88  // Is it a numeric value?
89  if ((is_numeric($arg)) && (!is_string($arg))) {
90  $mArgs[] = $arg;
91  }
92  }
93 
94  return $mArgs;
95  }
96 }
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:583