From 0c6cae0ef647158b9554cad05ff39db7e7ad0d33 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Feb 2023 21:19:28 +0300 Subject: [PATCH] fix empty --- src/Illuminate/Collections/Arr.php | 4 ++++ tests/Support/SupportArrTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index 66f5beb34979..8ef2e770fbcf 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -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--) { diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index cdd72c16f94a..a5aedae72983 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -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 = [