diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index 58c5e7829aa2..4e686eb93708 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -25,7 +25,7 @@ public static function accessible($value) * Add an element to an array using "dot" notation if it doesn't exist. * * @param array $array - * @param string $key + * @param string|int|float $key * @param mixed $value * @return array */ @@ -599,7 +599,7 @@ public static function random($array, $number = null, $preserveKeys = false) * If no key is given to the method, the entire array will be replaced. * * @param array $array - * @param string|null $key + * @param string|int|null $key * @param mixed $value * @return array */ diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index be70c8e2e99d..e854da50e0bf 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -32,6 +32,8 @@ public function testAdd() $this->assertEquals(['surname' => 'Mövsümov'], Arr::add([], 'surname', 'Mövsümov')); $this->assertEquals(['developer' => ['name' => 'Ferid']], Arr::add([], 'developer.name', 'Ferid')); + $this->assertEquals([1 => 'hAz'], Arr::add([], 1, 'hAz')); + $this->assertEquals([1 => [1 => 'hAz']], Arr::add([], 1.1, 'hAz')); } public function testCollapse() @@ -752,14 +754,8 @@ public function testSet() Arr::set($array, 'table.price', 350); $this->assertSame(['products' => ['desk' => ['price' => 100]], 'table' => ['price' => 350]], $array); - $array = []; - Arr::set($array, 'products.desk.price', 200); - $this->assertSame(['products' => ['desk' => ['price' => 200]]], $array); - - // Override - $array = ['products' => 'table']; - Arr::set($array, 'products.desk.price', 300); - $this->assertSame(['products' => ['desk' => ['price' => 300]]], $array); + $array = [1 => 'test']; + $this->assertEquals([1 => 'hAz'], Arr::set($array, 1, 'hAz')); } public function testShuffleWithSeed()