Skip to content

Commit 457b61c

Browse files
authored
Merge pull request #3347 from ConnectGrid/optimize-worksheet-from-array
Check $strictNullComparison outside of loops
2 parents ce16d0d + 5c6925d commit 457b61c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,23 +2784,30 @@ public function fromArray(array $source, mixed $nullValue = null, string $startC
27842784
[$startColumn, $startRow] = Coordinate::coordinateFromString($startCell);
27852785

27862786
// Loop through $source
2787-
foreach ($source as $rowData) {
2788-
$currentColumn = $startColumn;
2789-
foreach ($rowData as $cellValue) {
2790-
if ($strictNullComparison) {
2787+
if ($strictNullComparison) {
2788+
foreach ($source as $rowData) {
2789+
$currentColumn = $startColumn;
2790+
foreach ($rowData as $cellValue) {
27912791
if ($cellValue !== $nullValue) {
27922792
// Set cell value
27932793
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
27942794
}
2795-
} else {
2795+
++$currentColumn;
2796+
}
2797+
++$startRow;
2798+
}
2799+
} else {
2800+
foreach ($source as $rowData) {
2801+
$currentColumn = $startColumn;
2802+
foreach ($rowData as $cellValue) {
27962803
if ($cellValue != $nullValue) {
27972804
// Set cell value
27982805
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
27992806
}
2807+
++$currentColumn;
28002808
}
2801-
++$currentColumn;
2809+
++$startRow;
28022810
}
2803-
++$startRow;
28042811
}
28052812

28062813
return $this;

0 commit comments

Comments
 (0)