| 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 |
|