Skip to content
Permalink
Browse files

Fix Collection::transpose() with different number of columns and rows

Fixes #10137
  • Loading branch information...
Lucas-R committed Jan 31, 2017
1 parent b2b7f76 commit 5fec593769bafbe31d8d09cbdd4df0537a8d391b
Showing with 8 additions and 4 deletions.
  1. +3 −0 src/Collection/CollectionTrait.php
  2. +5 −4 tests/TestCase/Collection/CollectionTest.php
@@ -748,6 +748,9 @@ public function transpose()
if (count($row) != $length) {
throw new LogicException('Child arrays do not have even length');
}
}
for ($column = 0; $column < $length; $column++) {
$result[] = array_column($arrayValue, $column);
}
@@ -1932,13 +1932,14 @@ public function testTranspose()
['Product A', '200', '100', '50'],
['Product B', '300', '200', '100'],
['Product C', '400', '300', '200'],
['Product D', '500', '400', '300'],
]);
$transposed = $collection->transpose();
$expected = [
['Products', 'Product A', 'Product B', 'Product C'],
['2012', '200', '300', '400'],
['2013', '100', '200', '300'],
['2014', '50', '100', '200'],
['Products', 'Product A', 'Product B', 'Product C', 'Product D'],
['2012', '200', '300', '400', '500'],
['2013', '100', '200', '300', '400'],
['2014', '50', '100', '200', '300'],
];
$this->assertEquals($expected, $transposed->toList());

0 comments on commit 5fec593

Please sign in to comment.
You can’t perform that action at this time.