Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the opposite of array_dot #5663

Closed
wants to merge 4 commits into from
Closed

Conversation

danielsum
Copy link

Seems that I cannot find the opposite of the array_dot helpers so I made this very practical little helper to help me to transform an array with dot notation to a multidimensional object :

Ex :

$arrayDotted = [
'name' => 'name'
'data.categories.0' => 'cat-0',
'data.categories.1' => 'cat-1',
'data.location.name' => 'location name'
];

$response = dot_array($arrayDotted);

Will return a response like :

[
'name' => 'name'
'data' => [
'categories' => ['cat-0', 'cat-1'],
'location' => ['name' => 'location name']
];

The dot notation is very practical to flatten a multidimensional array with this helper you can use it in the opposite for example if you have data from a csv that you cannot have in a multidimensional way => you can use the dot notation an dot_array to handle this.

Seems that I cannot find the opposite of the array_dot helpers so I made this very practical little helper to help me to transform an array with dot notation to a multidimensional object : 

Ex : 

$arrayDotted = [
  'name' => 'name'
  'data.categories.0' => 'cat-0',
  'data.categories.1' => 'cat-1',
  'data.location.name' => 'location name'
];

$response = dot_array($arrayDotted);

Will return a response like : 

[
  'name' => 'name'
  'data' => [
    'categories' => ['cat-0', 'cat-1'],
    'location' => ['name' => 'location name']
];

The dot notation is very practical to flatten a multidimensional array with this helper you can use it in the opposite for example if you have data from a csv that you cannot have in a multidimensional way => you can use the dot notation an dot_array to handle this.
@GrahamCampbell
Copy link
Member

Maybe this stuff should be added to the Arr class?

@danielsum
Copy link
Author

yes certainly the correct place indeed

Daniel Sum added 3 commits September 6, 2014 10:51
Method moved to Arr class as suggested by GrahamCampbell 

See laravel#5663 (comment)
Method moved to Arr class as suggested by GrahamCampbell 

laravel#5663 (comment)
Moved to Arr::dot_array() method as suggested by GrahamCampbell

laravel#5663 (comment)
@taylorotwell
Copy link
Member

This can be added in your own helper file.

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.

None yet

3 participants