Skip to content

Add option to omit empty arrays from Arr::dot()#59669

Closed
johnstormentswe wants to merge 2 commits into
laravel:13.xfrom
johnstormentswe:feat/arr-dot-omit-empty-arrays
Closed

Add option to omit empty arrays from Arr::dot()#59669
johnstormentswe wants to merge 2 commits into
laravel:13.xfrom
johnstormentswe:feat/arr-dot-omit-empty-arrays

Conversation

@johnstormentswe

@johnstormentswe johnstormentswe commented Apr 13, 2026

Copy link
Copy Markdown

Adds an optional $preserveEmptyArrays parameter (default true) to Arr::dot() that, when set to false, omits keys whose values are empty arrays from the flattened output.

Default behavior is unchanged — existing callers continue to receive empty arrays preserved as [].

Closes #57305

Example

$data = ['foo' => 'bar', 'tags' => [], 'user' => ['name' => 'Taylor', 'roles' => []]];

Arr::dot($data);
// ['foo' => 'bar', 'tags' => [], 'user.name' => 'Taylor', 'user.roles' => []]

Arr::dot($data, '', INF, false);
// ['foo' => 'bar', 'user.name' => 'Taylor']

This makes the result directly usable with array_diff() and other functions that don't handle nested arrays.

Test plan

1. Added testDotOmittingEmptyArrays covering top-level, nested, and depth-limited cases
2. Existing testDot / testDotWithDepth still pass (82 assertions, 495 total)
3. vendor/bin/pint clean

@johnstormentswe
johnstormentswe marked this pull request as draft April 13, 2026 23:03
@johnstormentswe
johnstormentswe marked this pull request as ready for review April 13, 2026 23:03
@johnstormentswe
johnstormentswe marked this pull request as draft April 14, 2026 04:16
@johnstormentswe
johnstormentswe marked this pull request as ready for review April 14, 2026 04:16
@taylorotwell

Copy link
Copy Markdown
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arr::dot() doesn't flatten empty arrays

2 participants