diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 78b503bd4926..0ea82955c340 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1049,7 +1049,7 @@ public function partition($callback) $callback = $this->valueRetriever($callback); foreach ($this->items as $key => $item) { - $partitions[(int) ! $callback($item)][$key] = $item; + $partitions[(int) ! $callback($item, $key)][$key] = $item; } return new static($partitions); diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 39a2d1c78445..ffa46c8a7f78 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -2138,6 +2138,19 @@ public function testPartition() $this->assertEquals([6, 7, 8, 9, 10], $secondPartition->values()->toArray()); } + public function testPartitionCallbackWithKey() + { + $collection = new Collection(['zero', 'one','two', 'three']); + + list($even, $odd) = $collection->partition(function ($item, $index) { + return $index % 2 === 0; + }); + + $this->assertEquals(['zero', 'two'], $even->values()->toArray()); + + $this->assertEquals(['one', 'three'], $odd->values()->toArray()); + } + public function testPartitionByKey() { $courses = new Collection([