Skip to content

Commit 0c6cae0

Browse files
committed
fix empty
1 parent edbc590 commit 0c6cae0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Illuminate/Collections/Arr.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ public static function shuffle($array, $seed = null)
718718
return $array;
719719
}
720720

721+
if (empty($array)) {
722+
return [];
723+
}
724+
721725
$keys = array_keys($array);
722726

723727
for ($i = count($keys) - 1; $i > 0; $i--) {

tests/Support/SupportArrTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,11 @@ public function testShuffle()
860860
$this->assertTrue($dontMatch, 'Shuffled array should not have the same order.');
861861
}
862862

863+
public function testEmptyShuffle()
864+
{
865+
$this->assertEquals([], Arr::shuffle([]));
866+
}
867+
863868
public function testSort()
864869
{
865870
$unsorted = [

0 commit comments

Comments
 (0)