PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / LookupRef / Selection.php

Selection.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Selection.php

52 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8
9 class Selection
10 {
11 use ArrayEnabled;
12
13 /**
14 * CHOOSE.
15 *
16 * Uses lookup_value to return a value from the list of value arguments.
17 * Use CHOOSE to select one of up to 254 values based on the lookup_value.
18 *
19 * Excel Function:
20 * =CHOOSE(index_num, value1, [value2], ...)
21 *
22 * @param mixed $chosenEntry The entry to select from the list (indexed from 1)
23 * @param mixed ...$chooseArgs Data values
24 *
25 * @return mixed The selected value
26 */
27 public static function choose($chosenEntry, ...$chooseArgs)
28 {
29 if (is_array($chosenEntry)) {
30 return self::evaluateArrayArgumentsSubset([self::class, __FUNCTION__], 1, $chosenEntry, ...$chooseArgs);
31 }
32
33 $entryCount = count($chooseArgs) - 1;
34
35 if (is_numeric($chosenEntry)) {
36 --$chosenEntry;
37 } else {
38 return ExcelError::VALUE();
39 }
40 $chosenEntry = (int) floor($chosenEntry);
41 if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) {
42 return ExcelError::VALUE();
43 }
44
45 if (is_array($chooseArgs[$chosenEntry])) {
46 return Functions::flattenArray($chooseArgs[$chosenEntry]);
47 }
48
49 return $chooseArgs[$chosenEntry];
50 }
51 }
52