diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index 49b17766499a..4efe4d4e2d73 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -169,8 +169,12 @@ public static function dot($array, $prepend = '') foreach ($data as $key => $value) { $newKey = $prefix.$key; - if (is_array($value) && ! empty($value)) { - $flatten($value, $newKey.'.'); + if (is_array($value)) { + if (! empty($value)) { + $flatten($value, $newKey.'.'); + } else { + $results[$newKey] = null; + } } else { $results[$newKey] = $value; } @@ -597,7 +601,6 @@ public static function integer(ArrayAccess|array $array, string|int|null $key, ? * * An array is "associative" if it doesn't have sequential numerical keys beginning with zero. * - * @param array $array * @return bool */ public static function isAssoc(array $array) @@ -766,8 +769,6 @@ protected static function explodePluckParameters($value, $key) /** * Run a map over each of the items in the array. * - * @param array $array - * @param callable $callback * @return array */ public static function map(array $array, callable $callback) @@ -967,11 +968,6 @@ public static function set(&$array, $key, $value) /** * Push an item into an array using "dot" notation. - * - * @param \ArrayAccess|array $array - * @param string|int|null $key - * @param mixed $values - * @return array */ public static function push(ArrayAccess|array &$array, string|int|null $key, mixed ...$values): array { @@ -1152,7 +1148,6 @@ public static function toCssStyles($array) * Filter the array using the given callback. * * @param array $array - * @param callable $callback * @return array */ public static function where($array, callable $callback) @@ -1164,7 +1159,6 @@ public static function where($array, callable $callback) * Filter the array using the negation of the given callback. * * @param array $array - * @param callable $callback * @return array */ public static function reject($array, callable $callback) diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index ab5c2f2150a7..13504fb65a37 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -217,10 +217,10 @@ public function testDot() $this->assertSame([], $array); $array = Arr::dot(['foo' => []]); - $this->assertSame(['foo' => []], $array); + $this->assertSame(['foo' => null], $array); $array = Arr::dot(['foo' => ['bar' => []]]); - $this->assertSame(['foo.bar' => []], $array); + $this->assertSame(['foo.bar' => null], $array); $array = Arr::dot(['name' => 'taylor', 'languages' => ['php' => true]]); $this->assertSame(['name' => 'taylor', 'languages.php' => true], $array); @@ -243,7 +243,7 @@ public function testDot() $array = Arr::dot(['foo' => 'bar', 'empty_array' => [], 'user' => ['name' => 'Taylor'], 'key' => 'value']); $this->assertSame([ 'foo' => 'bar', - 'empty_array' => [], + 'empty_array' => null, 'user.name' => 'Taylor', 'key' => 'value', ], $array);