Skip to content

Commit

Permalink
fix empty
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 21, 2023
1 parent edbc590 commit 0c6cae0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ public static function shuffle($array, $seed = null)
return $array;
}

if (empty($array)) {
return [];
}

$keys = array_keys($array);

for ($i = count($keys) - 1; $i > 0; $i--) {
Expand Down
5 changes: 5 additions & 0 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,11 @@ public function testShuffle()
$this->assertTrue($dontMatch, 'Shuffled array should not have the same order.');
}

public function testEmptyShuffle()
{
$this->assertEquals([], Arr::shuffle([]));
}

public function testSort()
{
$unsorted = [
Expand Down

0 comments on commit 0c6cae0

Please sign in to comment.