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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Add undot array helper #33845

Closed
wants to merge 2 commits into from

Conversation

divspace
Copy link

Adds the inverse to the dot array helper by expanding array keys with "dot" notation into multi-dimensional arrays.

Besides adding the inverse functionality, there are times when certain functions/methods in your code may not allow multi-dimensional arrays and you need a way to pass flattened "dot" notated arrays to them (or maybe you find the syntax easier to write). For example, if you were to add a message with something like:

$messages = new MessageBag([
    'error.code' => 403,
    'error.message' => 'Unauthorized request',
]);

You could store those messages correctly, and after retrieving them, simply undot the messages to get a proper array:

[
  'error' => [
    'code' => 403,
    'message' => 'Unauthorized request'
  ]
]

This does not break existing functionality since it's a new helper and tests have been provided.

This is my first pull request ever to a project that isn't work related, so hopefully I did this right (even watched Jeffrey Way's video on Laracasts). I think I spent more time writing the method's description than anything else 馃槵

@divspace divspace changed the title Add undot array helper [7.x] Add undot array helper Aug 13, 2020
@mnabialek
Copy link
Contributor

@divspace
Copy link
Author

Oh, didn鈥檛 even think to search first. Oh well, close this then I鈥檒l just keep extending Arr out 馃

@divspace divspace closed this Aug 13, 2020
@divspace divspace deleted the add-undot-array-helper branch August 26, 2020 21:45
@divspace divspace restored the add-undot-array-helper branch August 26, 2020 21:45
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

2 participants