Skip to content

Add depth parameter to Arr::dot()#59150

Open
faytekin wants to merge 1 commit intolaravel:12.xfrom
faytekin:arr-dot-depth
Open

Add depth parameter to Arr::dot()#59150
faytekin wants to merge 1 commit intolaravel:12.xfrom
faytekin:arr-dot-depth

Conversation

@faytekin
Copy link

Arr::flatten() has a $depth parameter to control how deep it goes but Arr::dot() always flattens everything. this adds the same $depth parameter to Arr::dot() for consistency.

Usage

$array = ['user' => ['name' => 'Taylor', 'address' => ['city' => 'Dallas']]];

// current behavior, nothing changes
Arr::dot($array);
// ['user.name' => 'Taylor', 'user.address.city' => 'Dallas']

// only 1 level
Arr::dot($array, '', 1);
// ['user.name' => 'Taylor', 'user.address' => ['city' => 'Dallas']]

also works on collections:

collect($array)->dot(1);

default value is INF so existing usage is not affected.

@nrzky
Copy link

nrzky commented Mar 10, 2026

Nice addition. Having the same $depth behavior as Arr::flatten() makes the API more consistent and gives more control when working with partially flattened structures. I can see this being useful in several cases.

@mertasan
Copy link
Contributor

Mirrors Arr::flatten()'s $depth behavior — which was the first thing I checked. This actually replaces some custom methods I had around partial dot-flattening.

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.

3 participants