Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading