Conditions | 8 |
Paths | 54 |
Total Lines | 32 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | public static function hstack(mixed ...$inputData): array|string |
||
16 | { |
||
17 | $maxRow = 0; |
||
18 | foreach ($inputData as $matrix) { |
||
19 | if (!is_array($matrix)) { |
||
20 | $count = 1; |
||
21 | } else { |
||
22 | $count = count($matrix); |
||
23 | } |
||
24 | $maxRow = max($maxRow, $count); |
||
25 | } |
||
26 | /** @var mixed[] $inputData */ |
||
27 | foreach ($inputData as &$matrix) { |
||
28 | if (!is_array($matrix)) { |
||
29 | $matrix = [$matrix]; |
||
30 | } |
||
31 | $rows = count($matrix); |
||
32 | $reset = reset($matrix); |
||
33 | $columns = is_array($reset) ? count($reset) : 1; |
||
34 | while ($maxRow > $rows) { |
||
35 | $matrix[] = array_pad([], $columns, ExcelError::NA()); |
||
36 | ++$rows; |
||
37 | } |
||
38 | } |
||
39 | |||
40 | $transpose = array_map(null, ...$inputData); //* @phpstan-ignore-line |
||
41 | $returnMatrix = []; |
||
42 | foreach ($transpose as $array) { |
||
43 | $returnMatrix[] = Functions::flattenArray($array); |
||
44 | } |
||
45 | |||
46 | return $returnMatrix; |
||
47 | } |
||
49 |