diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 7cea45540d60..75690a854ceb 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -352,7 +352,7 @@ public function each(callable $callback) public function eachSpread(callable $callback) { return $this->each(function ($chunk, $key) use ($callback) { - array_push($chunk, $key); + $chunk[] = $key; return $callback(...$chunk); }); @@ -844,7 +844,7 @@ public function map(callable $callback) public function mapSpread(callable $callback) { return $this->map(function ($chunk, $key) use ($callback) { - array_push($chunk, $key); + $chunk[] = $key; return $callback(...$chunk); }); diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index d1c82fccc0b3..3b262524b3b6 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -606,6 +606,13 @@ public function testEachSpread() $result[] = [$number, $character, $key]; }); $this->assertEquals([[1, 'a', 0], [2, 'b', 1]], $result); + + $c = new Collection([new Collection([1, 'a']), new Collection([2, 'b'])]); + $result = []; + $c->eachSpread(function ($number, $character, $key) use (&$result) { + $result[] = [$number, $character, $key]; + }); + $this->assertEquals([[1, 'a', 0], [2, 'b', 1]], $result); } public function testIntersectNull() @@ -1225,6 +1232,12 @@ public function testMapSpread() return "{$number}-{$character}-{$key}"; }); $this->assertEquals(['1-a-0', '2-b-1'], $result->all()); + + $c = new Collection([new Collection([1, 'a']), new Collection([2, 'b'])]); + $result = $c->mapSpread(function ($number, $character, $key) use (&$result) { + return "{$number}-{$character}-{$key}"; + }); + $this->assertEquals(['1-a-0', '2-b-1'], $result->all()); } public function testFlatMap()