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 / Hstack.php

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

50 lines 1.2 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\Functions;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
7
8 class Hstack
9 {
10 /**
11 * Excel function HSTACK.
12 *
13 * @return mixed[]|string
14 * @param mixed ...$inputData
15 */
16 public static function hstack(...$inputData)
17 {
18 $maxRow = 0;
19 foreach ($inputData as $matrix) {
20 if (!is_array($matrix)) {
21 $count = 1;
22 } else {
23 $count = count($matrix);
24 }
25 $maxRow = max($maxRow, $count);
26 }
27 /** @var mixed[] $inputData */
28 foreach ($inputData as &$matrix) {
29 if (!is_array($matrix)) {
30 $matrix = [$matrix];
31 }
32 $rows = count($matrix);
33 $reset = reset($matrix);
34 $columns = is_array($reset) ? count($reset) : 1;
35 while ($maxRow > $rows) {
36 $matrix[] = array_pad([], $columns, ExcelError::NA());
37 ++$rows;
38 }
39 }
40
41 $transpose = array_map(null, ...$inputData); //* @phpstan-ignore argument.type (inputData is mixed not array)
42 $returnMatrix = [];
43 foreach ($transpose as $array) {
44 $returnMatrix[] = Functions::flattenArray($array);
45 }
46
47 return $returnMatrix;
48 }
49 }
50